Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
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
Old 09-15-2011, 10:17 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Does your code work? That looks pretty close to the right way to do it.
Inigoesdr is offline   Reply With Quote
Old 09-15-2011, 10:38 PM   PM User | #3
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
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.
Vladq is offline   Reply With Quote
Reply

Bookmarks

Tags
air, flex, image

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:50 PM.


Advertisement
Log in to turn off these ads.