2 Replies Latest reply on Mar 9, 2008 7:28 AM by Starlover_jacob

    reduce image size

    Starlover_jacob Level 1
      Hello,

      I have a question about reducing the size of an image.
      What i want is to load an image.. resize it and then save it into a blob(sqlite air db)

      In php you say imagecopyresampled and you can save a smaller image.

      How to do this in flex?

      What i have is an function witch resizes the given image, but i doubt the image is really reduced in size..(from 900 to 100k)

      code:


      package
      {
      import flash.display.Bitmap;

      public class imageresize extends Bitmap
      {
      //globals
      private var bmp:Bitmap;
      private var true_width:Number;
      private var true_height:Number;
      private var maxx:Number;
      private var maxy:Number;
      private var resize:Boolean;
      public function resizeImage(b:Bitmap,h:Number,w:Number):Bitmap
      {
      this.bmp=b;
      this.maxx=w;
      this.maxy=h;
      this.true_width = bmp.width;
      this.true_height = bmp.height;
      //this.true_width2 = imagesx($image);
      //this.true_height2 = imagesy($image);
      this.resize=false;

      if (true_width>maxx) resize=true;
      if (true_height>maxy) resize=true;
      if (resize==true)
      {
      var width:Number=maxx;
      var height:Number = (width / true_width) * true_height;
      true_width=width;
      true_height=height;

      if (true_height>maxy)
      {
      height=maxy;
      width = (height/true_height)*true_width;
      }
      else
      {
      width=true_width;
      height=true_height;
      }
      }
      else
      {
      width=true_width;
      height=true_height;
      }

      width=Math.ceil(width);
      height=Math.ceil(height);

      // this is used extra in php to get a smaller image
      //$dest_img = imagecreatetruecolor($width, $height);
      //imagecopyresampled(
      // $dest_img, $image,
      // 0, 0, 0, 0,
      // $width, $height, $true_width2, $true_height2); // resize the image
      //return $dest_img;
      bmp.height=height;
      bmp.width=width;
      return bmp;
      }

      }
      }



      please some help here,sorry for the way i put the code here.. i couldn't find the attach code button..
      or did i have to use [attach code]? maybe handy to change the string attach code into a link..

      Greets, jacob