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();
}
}