Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Does your code work? That looks pretty close to the right way to do it.

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •