View Single Post
Old 09-15-2011, 07:42 PM   PM User | #1
Vladq
New to the CF scene

 
Join Date: Sep 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Vladq is an unknown quantity at this point
How to make thumbnail for image

Hi.
I want to make thumbnail for selected image from local disk, but I don't know what is the proper way to do this.

(this is all in AIR application)

Here is the code that I try to use:
Code:
// I select files from disk
protected function selectTextFile(root:File):void
{
 var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
 root.browseForOpenMultiple("Select Files", [imageTypes]);
 root.addEventListener(FileListEvent.SELECT_MULTIPLE, filesSelected);
}
// Then I try to make thumbnail for each
protected function filesSelected(event:FileListEvent):void
{
var image_temp:Image;
 var width:Number = 100; // size of thumbnail
 var height:Number = 100;// size of thumbnail

 for (var i:uint = 0; i < event.files.length; i++) 
 {
 image_temp = new Image();
 image_temp.source = event.files[i].nativePath;

 var bitmapData:BitmapData;
 bitmapData=new BitmapData(image_temp.width, image_temp.height); //here is error "ArgumentError: Error #2015: Invalid BitmapData."
 var matrix:Matrix = new Matrix();
 matrix.scale(width / image_temp.width, height / image_temp.height); // scaling the image
 bitmapData.draw(image_temp,matrix);

 // saving thumbnail to desktop          &n bsp;               
 var save:File = File.desktopDirectory.resolvePath("thumb_"+event.files[i].name);
 var fs:FileStream = new FileStream();
 fs.open(save,FileMode.WRITE);
 fs.writeObject(bitmapData);
 fs.close();
 }
}
Vladq is offline   Reply With Quote