Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Bitmap.smoothing - how to reduce image distortion

This is a discussion on Bitmap.smoothing - how to reduce image distortion within the Tutorials forums, part of the Flash English category; I received more questions regarding the 3D image viewer . Mainly, those questions was about the fact of expanding images with ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  3 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 23-09-07, 17:17
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Bitmap.smoothing - how to reduce image distortion

I received more questions regarding the 3D image viewer .
Mainly, those questions was about the fact of expanding images with as less as possible distortion of the image itself.
Some emails would specify that the image used were of high resolution which is wrong to start with.

The trick to avoid the distortion of images used in animations is simply in the settings of one parameter.* In your flash library, if you right click on the image, you will find the option ‘Allow smoothing’.* Once that option checked, Flash will drastically reduce the image distortion during the animation.

Now, what should we do if the image is not placed in library but is externally loaded in runtime?

The answer is the property ‘smoothing’ of the Bitmap Class of Actionscript 3.0.

Let us take a look at those2 following examples:













In the first example, the property ‘smoothing’ is set to ‘false’. In the second, the property ‘smoothing’ is set to ‘true’.

I create a FLA and save it as ‘main.fla’.
This FLA is empty.
We will assign to it a Document Class, an AS file saved as ‘Main.as’, implemented the following way:
Code:
package
{
	import flash.display.MovieClip;
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.events.Event;
	
	public class Main extends MovieClip
	{
		private var loader:Loader;
		
		private var startWidth:Number;
		private var startHeight:Number;
		
		public function Main()
		{
			init();
			loadImage();
		}
		
		private function init():void
		{
			stage.frameRate=31;
		}
		
		private function loadImage():void
		{
			var request:URLRequest=new URLRequest('http://www.flepstudio.org/swf/sintassi/allow_smoothing/pic_0.jpg');
			loader=new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completed);
			loader.load(request);
		}
		
		private function completed(evt:Event):void
		{
			addChild(loader);
			startWidth=loader.width;
			startHeight=loader.height;
			loader.addEventListener(Event.ENTER_FRAME,moveMe);
		}
		
		private function moveMe(evt:Event):void
		{
			evt.target.width+=2;
			evt.target.height+=2;
			if(evt.target.width>stage.stageWidth)
			{
				evt.target.width=startWidth;
				evt.target.height=startHeight;
			}
		}
	}
}
As we can see from the code, an external image is loaded via a Loader.
Once completely loaded, I apply to ‘loader’ (instance of Loader which loaded the image) an animation. The content of ‘loader’ is enlarged in both width and height.
In this case, we do not use the property ‘smoothing’ and the result is not one of the best to see.

Instead, if when ‘loader’ has finished to completely load the image (in the method: private function completed), we write those few next lines of codes:

I add ‘loader’ to the stage (otherwise it would not be visible)
addChild(loader);
I create a Bitmap variable to which I assign as a value the content of ‘loader’ and force it a Bitmap type
var image:Bitmap=loader.content as Bitmap;
I assign ‘true’ to the property ‘smoothing’ of ’image’
image.smoothing=true;
This way, the result is a lot better.
We took out the best we could of an image of 280x187px and of only 8KB!

See you soon!
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 24-10-07, 18:10
Junior Member
 
Join Date: Sep 2007
Posts: 8
Rep Power: 0
guitarman is on a distinguished road
Re: Bitmap.smoothing ? how to reduce image distortion

Hey Flep,

Thanks so much for your incredible tutorials and help. I'm a 2.0 programmer just now learning 3. I was gonna ask you a question but i figured it out as I was writing this!

Thanks again,

guitarman
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 21-05-08, 08:51
Junior Member
 
Join Date: Apr 2008
Posts: 3
Rep Power: 0
dan.groza is on a distinguished road
re: Bitmap.smoothing - how to reduce image distortion

Hello, Flep
I have just opened a thread about loading external swf, I need to do something the same you did above, but with a swf file instead of an image.

Can you help me? I get an error message when casting from Loader to Bitmap.

Thank you,
Dan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 21-05-08, 09:15
Junior Member
 
Join Date: Apr 2008
Posts: 3
Rep Power: 0
dan.groza is on a distinguished road
re: Bitmap.smoothing - how to reduce image distortion

Quote:
Originally Posted by dan.groza View Post
Hello, Flep
I have just opened a thread about loading external swf, I need to do something the same you did above, but with a swf file instead of an image.

Can you help me? I get an error message when casting from Loader to Bitmap.

Thank you,
Dan
PS: I have modified your code:

package
{
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Bitmap;
import flash.display.BitmapData;

public class Main extends MovieClip
{
private var loader:Loader;

private var startWidth:Number;
private var startHeight:Number;


private var image:Bitmap;

public function Main()
{
init();
loadImage();
}

private function init():void
{
stage.frameRate=31;
}

private function loadImage():void
{
var request:URLRequest=new URLRequest('img.jpg'); // it works with image files, but not with swf.
loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE,completed);
loader.load(request);
}

private function completed(evt:Event):void
{
addChild(loader);
startWidth=loader.width;
startHeight=loader.height;
loader.addEventListener(Event.ENTER_FRAME,moveMe);


image = loader.content as Bitmap;
image.smoothing=true;
addChild(image);
image.x = 400;

}

private function moveMe(evt:Event):void
{
evt.target.width+=2;
evt.target.height+=2;
if(evt.target.width>stage.stageWidth)
{
evt.target.width=startWidth;
evt.target.height=startHeight;
}
}
}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 28-05-08, 22:13
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
re: Bitmap.smoothing - how to reduce image distortion

Code:
private var image:MovieClip;
...

Code:
image = loader.content as MovieClip;
//image.smoothing=true;
addChild(image);
image.x = 400;
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Actionscript 3 Preloader con Bitmap Lit Actionscript 3.0 avanzato 0 14-09-08 20:57
Actionscript 3 trasparenza bitmap con alone acca2o Actionscript 3.0 avanzato 0 07-09-08 09:51
swf to bitmap dan.groza Actionscript 3.0 avanzato 1 28-05-08 22:49
Bitmap Pixelate image transition help guitarman Flash English 1 01-02-08 08:16
Bitmap.smoothing - come diminuire la distorsione delle immagini Flep Articoli e tutorials 0 21-09-07 10:34


All times are GMT. The time now is 13:39.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap