Quantcast
Channel: Adobe Community : Popular Discussions - Archived Discussions
Viewing all articles
Browse latest Browse all 21156

using jpegEncoder object and filesystem

$
0
0
Hi, I also posted this in the Flex general forum, but it seems to be more AIR related since it deals with saving to the local disk. I am trying to create a simple AIR application that creates a thumbnail from an image component and saves it as a jpeg to the desktop. I am not sure where I am going wrong here, but the file is corrupt and no information is being written to it. If I look at the content (via the "more" command on the command line) it is 8 blank lines.

Thanks so much,
Jed

=========

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

<mx:Script>
<![CDATA[

import mx.graphics.ImageSnapshot;
import mx.graphics.codec.*;
import mx.events.FileEvent;

private function captureImg():void{

//captures the image as a jpg and saves it to the desktop

var codec:JPEGEncoder = new JPEGEncoder();
//var ba:ByteArray = new ByteArray;
var file:File = File.desktopDirectory.resolvePath("test.jpg");
var filestream:FileStream = new FileStream;
var snapShot:ImageSnapshot = new ImageSnapshot;

snapShot = ImageSnapshot.captureImage(bigImg,72,codec);

filestream.open(file, FileMode.WRITE);
filestream.writeBytes(
codec.encodeByteArray(snapShot.data,420,120),0,snapShot.data.length);
filestream.close();
}


private function makeSmall():void{

//makes the image on the screen thumbnail size

var pic:Image = bigImg;
pic.setActualSize(420, 120);
}

]]>
</mx:Script>

<mx:VBox horizontalAlign="center" verticalAlign="top">
<mx:Image id="bigImg" width="480" height="320" source="orignial/test2.jpg"/>
<mx:Button label="Reduce Size" id="btnSmaller" click="makeSmall();" />
<mx:Button label="Snap Thumbnail" id="btnThumbnail" click="captureImg();"/>
</mx:VBox>

</mx:WindowedApplication>

Text

Viewing all articles
Browse latest Browse all 21156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>