CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Adobe Flex (http://www.codingforums.com/forumdisplay.php?f=63)
-   -   How to make thumbnail for image (http://www.codingforums.com/showthread.php?t=238184)

Vladq 09-15-2011 07:42 PM

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


Inigoesdr 09-15-2011 10:17 PM

Does your code work? That looks pretty close to the right way to do it.

Vladq 09-15-2011 10:38 PM

Unfortunetly it don't work. In the code I marked the place where error occurs.
It's the part when I try to create bitmapData from width and height of the image_temp
Code:

bitmapData=new BitmapData(image_temp.width, image_temp.height);
The error says ArgumentError: Error #2015: Invalid BitmapData.

So I think I'm doing something wrong, but I don't know what, and how to fix this.


All times are GMT +1. The time now is 01:54 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.