Re: [Flashcoders] What is the best way to scale a bitmap specifically to reduce file size...

2008-11-25 Thread Latcho

file size is something else then memory size.
If you want a smaller swf size, you have to make the source image 
smaller within the fla or before embedding it via code.

So be more specific.
But I think you are after this:

import flash.geom.*;
import flash.display.BitmapData;
import flash.display.Bitmap;

//var container:Sprite = ...I assume you have a container Sprite;

// 10 times smaller
var scaleFactor:Number = 0.1;

var matrix:Matrix = new Matrix ();
matrix.scale (scaleFactor, scaleFactor); // x and y scale

var bmpData:BitmapData = new BitmapData( 
int(container.width*scaleFactor), int(container.height*scaleFactor) );

bmpData.draw(container,matrix)

addChild(new Bitmap(bmpData,"auto",true)); // arguments: 
bmp,pixelsnapping,smoothing

removeChild(container)

More nice examples on Matrix here:
http://jasu.tistory.com/228

Latcho

Anthony Pace wrote:

Now when I scale the image it won't display... OMG.  this is nuts.

I thought I had it all figured out, and then wham... it won't work.

Glen Pike wrote:

|Hi,

Something like this:

import flash.display.Bitmap;
import flash.display.BitmapData;

//original image in here
container.width /= 10;
||container.height /= 10;|

//maybe invalidate if it does not redraw??
|
var a:BitmapData = new BitmapData(container.width, container.height);
var b:Bitmap = new Bitmap(a);

addChild(b);

a.draw(container);
container.visible = false;|



Anthony Pace wrote:

Examples?



Glen Pike wrote:

Hi,

   The only way to reduce the memory size of a bitmap is to resize 
it and reduce the number of pixels.


   If you are loading images from the server, you might want to 
think about generating smaller images server side - you may only 
have to do this once when the image is uploaded, so this may be 
more useful if you don't require lots of different sizes / unknown 
sizes at runtime - depends on the project.  Wordpress among other 
things does this quite nicely for you at upload time (when the 
Wordpress coders stop moaning about FP10 and fix the uploader, it 
will be even nicer) and there are lots of scripts which are 
variations - resize on the fly & cache, etc.


   For client side - reduce the size of the container, then draw 
the bitmap image of this into a new bitmap data object - you should 
then have a smaller image and you could discard your container'd one.


   Glen

Anthony Pace wrote:
I can do it by reducing the size of the container object; yet, the 
bitmap remains the same file sized and can be scaled well.


Is there a way to guarantee the memory usage drops?  or at least a 
better way then mine?

___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders






___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders






___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] What is the best way to scale a bitmap specifically to reduce file size...

2008-11-25 Thread Anthony Pace

Now when I scale the image it won't display... OMG.  this is nuts.

I thought I had it all figured out, and then wham... it won't work.

Glen Pike wrote:

|Hi,

Something like this:

import flash.display.Bitmap;
import flash.display.BitmapData;

//original image in here
container.width /= 10;
||container.height /= 10;|

//maybe invalidate if it does not redraw??
|
var a:BitmapData = new BitmapData(container.width, container.height);
var b:Bitmap = new Bitmap(a);

addChild(b);

a.draw(container);
container.visible = false;|



Anthony Pace wrote:

Examples?



Glen Pike wrote:

Hi,

   The only way to reduce the memory size of a bitmap is to resize 
it and reduce the number of pixels.


   If you are loading images from the server, you might want to 
think about generating smaller images server side - you may only 
have to do this once when the image is uploaded, so this may be more 
useful if you don't require lots of different sizes / unknown sizes 
at runtime - depends on the project.  Wordpress among other things 
does this quite nicely for you at upload time (when the Wordpress 
coders stop moaning about FP10 and fix the uploader, it will be even 
nicer) and there are lots of scripts which are variations - resize 
on the fly & cache, etc.


   For client side - reduce the size of the container, then draw the 
bitmap image of this into a new bitmap data object - you should then 
have a smaller image and you could discard your container'd one.


   Glen

Anthony Pace wrote:
I can do it by reducing the size of the container object; yet, the 
bitmap remains the same file sized and can be scaled well.


Is there a way to guarantee the memory usage drops?  or at least a 
better way then mine?

___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders






___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders






___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] What is the best way to scale a bitmap specifically to reduce file size...

2008-11-25 Thread Anthony Pace

Cool,

I was actually trying out my own when posted.  the live docs have some 
good info about display programming, and now that I have been assured it 
wil reduce bloat, I am going ahead with it.


I also came up with a cute little way to generate thumbs if the image 
doesn't format, and I figured that I can extend it once I have time to 
make use of the elements of photography as rules to detect visual 
interest.  (contrast, positive negative space, rule of thirds, balance, 
line and direction analyses.)  Put them together, and you have the 
perfect thumbnail.  hahahaha


thanks for the tip on .draw

Thanks,
Anthony


Glen Pike wrote:

|Hi,

Something like this:

import flash.display.Bitmap;
import flash.display.BitmapData;

//original image in here
container.width /= 10;
||container.height /= 10;|

//maybe invalidate if it does not redraw??
|
var a:BitmapData = new BitmapData(container.width, container.height);
var b:Bitmap = new Bitmap(a);

addChild(b);

a.draw(container);
container.visible = false;|



Anthony Pace wrote:

Examples?



Glen Pike wrote:

Hi,

   The only way to reduce the memory size of a bitmap is to resize 
it and reduce the number of pixels.


   If you are loading images from the server, you might want to 
think about generating smaller images server side - you may only 
have to do this once when the image is uploaded, so this may be more 
useful if you don't require lots of different sizes / unknown sizes 
at runtime - depends on the project.  Wordpress among other things 
does this quite nicely for you at upload time (when the Wordpress 
coders stop moaning about FP10 and fix the uploader, it will be even 
nicer) and there are lots of scripts which are variations - resize 
on the fly & cache, etc.


   For client side - reduce the size of the container, then draw the 
bitmap image of this into a new bitmap data object - you should then 
have a smaller image and you could discard your container'd one.


   Glen

Anthony Pace wrote:
I can do it by reducing the size of the container object; yet, the 
bitmap remains the same file sized and can be scaled well.


Is there a way to guarantee the memory usage drops?  or at least a 
better way then mine?

___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders






___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders






___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] What is the best way to scale a bitmap specifically to reduce file size...

2008-11-25 Thread Glen Pike

|Hi,

Something like this:

import flash.display.Bitmap;
import flash.display.BitmapData;

//original image in here
container.width /= 10;
||container.height /= 10;|

//maybe invalidate if it does not redraw??
|
var a:BitmapData = new BitmapData(container.width, container.height);
var b:Bitmap = new Bitmap(a);

addChild(b);

a.draw(container);
container.visible = false;|



Anthony Pace wrote:

Examples?



Glen Pike wrote:

Hi,

   The only way to reduce the memory size of a bitmap is to resize it 
and reduce the number of pixels.


   If you are loading images from the server, you might want to think 
about generating smaller images server side - you may only have to do 
this once when the image is uploaded, so this may be more useful if 
you don't require lots of different sizes / unknown sizes at runtime 
- depends on the project.  Wordpress among other things does this 
quite nicely for you at upload time (when the Wordpress coders stop 
moaning about FP10 and fix the uploader, it will be even nicer) and 
there are lots of scripts which are variations - resize on the fly & 
cache, etc.


   For client side - reduce the size of the container, then draw the 
bitmap image of this into a new bitmap data object - you should then 
have a smaller image and you could discard your container'd one.


   Glen

Anthony Pace wrote:
I can do it by reducing the size of the container object; yet, the 
bitmap remains the same file sized and can be scaled well.


Is there a way to guarantee the memory usage drops?  or at least a 
better way then mine?

___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders






___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--

Glen Pike
01326 218440
www.glenpike.co.uk 

___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] What is the best way to scale a bitmap specifically to reduce file size...

2008-11-25 Thread Anthony Pace

Examples?



Glen Pike wrote:

Hi,

   The only way to reduce the memory size of a bitmap is to resize it 
and reduce the number of pixels.


   If you are loading images from the server, you might want to think 
about generating smaller images server side - you may only have to do 
this once when the image is uploaded, so this may be more useful if 
you don't require lots of different sizes / unknown sizes at runtime - 
depends on the project.  Wordpress among other things does this quite 
nicely for you at upload time (when the Wordpress coders stop moaning 
about FP10 and fix the uploader, it will be even nicer) and there are 
lots of scripts which are variations - resize on the fly & cache, etc.


   For client side - reduce the size of the container, then draw the 
bitmap image of this into a new bitmap data object - you should then 
have a smaller image and you could discard your container'd one.


   Glen

Anthony Pace wrote:
I can do it by reducing the size of the container object; yet, the 
bitmap remains the same file sized and can be scaled well.


Is there a way to guarantee the memory usage drops?  or at least a 
better way then mine?

___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders






___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] What is the best way to scale a bitmap specifically to reduce file size...

2008-11-25 Thread Glen Pike

Hi,

   The only way to reduce the memory size of a bitmap is to resize it 
and reduce the number of pixels.


   If you are loading images from the server, you might want to think 
about generating smaller images server side - you may only have to do 
this once when the image is uploaded, so this may be more useful if you 
don't require lots of different sizes / unknown sizes at runtime - 
depends on the project.  Wordpress among other things does this quite 
nicely for you at upload time (when the Wordpress coders stop moaning 
about FP10 and fix the uploader, it will be even nicer) and there are 
lots of scripts which are variations - resize on the fly & cache, etc.


   For client side - reduce the size of the container, then draw the 
bitmap image of this into a new bitmap data object - you should then 
have a smaller image and you could discard your container'd one.


   Glen

Anthony Pace wrote:
I can do it by reducing the size of the container object; yet, the 
bitmap remains the same file sized and can be scaled well.


Is there a way to guarantee the memory usage drops?  or at least a 
better way then mine?

___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--

Glen Pike
01326 218440
www.glenpike.co.uk 

___
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders