PDA

View Full Version : Disappointed with load external jpg


csdstudio
11-16-2005, 03:59 PM
It would appear that an externally loaded image has no smoothing quality. When rotated or scaled via actionscript after loaded, it's very pixelated. I can't seem to find a way around this downfall. This is not good. I see that attachBitmap has a smoothing option, but it would seem a long round about direction is the only way to get a loaded jpg into a Bitmap data object and than attachBitmap, I'm at a loss if that's what is needed. I'm still confused with the new Bitmap data methods :(

Any ideas?

:confused:

csdstudio
11-16-2005, 04:22 PM
I should really do my own expirementing before posting, I figured out how to smooth an externally loaded image. I am happy now.

CyanBlue
11-16-2005, 04:40 PM
Howdy... :)

It'd be great if you could share what you have found out... You never know who will have the same question and looking for an answer... ;)

csdstudio
11-16-2005, 05:01 PM
Howdy... :)

It'd be great if you could share what you have found out... You never know who will have the same question and looking for an answer... ;)

Absolutely, I don't mind sharing my earned knowledge. :p I hope this will help others too...

The following loads an image into mc original, then creates a bitmapData and applies it to mc smooth, then removes the original mc. There is a noticeable difference, which can be seen by commenting these two lines to do a comparison:

smooth.attachBitmap(bmpData1, 2, "auto", true);
original.removeMovieClip();


import flash.display.*;
var srcImg = "bmp1.png";
var mainHolder = this.createEmptyMovieClip("main", this.getNextHighestDepth());
var original = mainHolder.createEmptyMovieClip("original", mainHolder.getNextHighestDepth());
var smooth = mainHolder.createEmptyMovieClip("smooth", mainHolder.getNextHighestDepth());
var mclListener:Object = new Object();
mclListener.onLoadInit = function() {
var w = original._width;
var h = original._height;
var bmpData1:BitmapData = new BitmapData(w, h, true, 0x000000); //true and 0 color allows for transparency
bmpData1.draw(original);
smooth.attachBitmap(bmpData1, 2, "auto", true); //true for SMOOTHING, ;)
original.removeMovieClip();
};
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip(srcImg, original);
main._rotation = 25;


This works with transparent pngs just fine too. I guess the bitmapData method isn't as strange as I thought it was. :p

CyanBlue
11-16-2005, 05:34 PM
Hm... That's very interesting yet cumbersome approach... That blame goes to MM, oh well... Thanks for sharing it... ;)

oldnewbie
11-16-2005, 07:56 PM
Adding the following on the first frame...

_quality = "BEST";

Usually solved that problem before Flash 8.

csdstudio
11-16-2005, 09:18 PM
Adding the following on the first frame...

_quality = "BEST";

Usually solved that problem before Flash 8.

Not for 8. MM's default for loaded images would appear to be no smoothing enabled. Quality setting has no effect if the smoothing is disabled on an image. :( Same for when I import images into the IDE, their allow smoothing setting is unchecked by default. That wasn't the case before 8 either.

stesmi99
09-25-2006, 06:40 AM
that is a really sweet bit of code that. very happy as I did not think there was a solution to such a thing! thanks.

Flash Gordon
09-25-2006, 07:01 AM
Here is a class to take care of it:

import flash.display.BitmapData; //import the BitmapData class

class Smooth {

private var bmd:BitmapData; // the BitmapData instance that will smooth the image

public function Smooth(copy:MovieClip) {
bmd = new BitmapData(copy._width, copy._height, true, 0); // create the instance to the right dimensions
bmd.draw(copy); // copy the image into the instance

copy.unloadMovie(); // unload the original movie
copy.attachBitmap(bmd, 0, "auto", true); // attach the bmd instance and apply smoothing
}
}

in FLA

var image:String = "http://www.wallpaperbase.com/wallpapers/celebs/hilaryswank/hilary_swank_3.jpg";
var holder:MovieClip = this.createEmptyMovieClip("holder", this.getNextHighestDepth());

var mcl_L:Object = new Object();
mcl_L.onLoadInit = function() {
new Smooth(holder); // here we use the class
holder._rotation = 25;
};

var mcl:MovieClipLoader = new MovieClipLoader();
mcl.addListener(mcl_L);
mcl.loadClip(image, holder);

Flash Gordon
09-29-2006, 03:35 AM
Any idea why this class doesn't work when I try to pull a picture in locally? Something about the copy.unloadMovie(); doesn't work right locally, but it work's just fine in the example above.

Attached are my files.

pixelwit
11-17-2006, 09:52 AM
I think the problem is that unloadMovie works asynchronously. The ActionScript Definitive Guide states that unloadMovie is only executed when all other scripts in the current frame have completed.

So basically, you're copying the clip's content into the bitmapData, instantly attaching the bitmapData to the clip, and then moments later unloading that clip's entire contents (including the bitmapData).

But if that's the case, I don't understand how your code would work as expected but you say it does. Muy misterioso.

-PiXELWiT
http://www.pixelwit.com

Peter Cohen
12-07-2006, 05:35 AM
Hi folks. Thanks for the code. Due to logon problems earlier I posted my solution based on yours over at ultrashock (http://forums.ultrashock.com/ff.htm?http://forums.ultrashock.com/forums/showthread.php?s=&threadid=75227&highlight=smoothing). Solves the unloadmovie problem and also the problem they were having with losing property values like (_rotation, _alpha, etc).

Arcmedia
advanced multimedia solutions

www.arcmedia.com.au

Flash Gordon
12-07-2006, 06:41 AM
I think the problem is that unloadMovie works asynchronously. The ActionScript Definitive Guide states that unloadMovie is only executed when all other scripts in the current frame have completed.


Didn't understand what you meant until today, so I put off replying. Below is a little test

var m:MovieClip = this.createEmptyMovieClip("m", 0);
m.lineStyle(40);
m.lineTo(.5, 0);
m._x = m._y = 200;

m.unloadMovie();
// removeMovieclip() would work here instead of
// unloadMovie() as long as you created it again

var bmp:flash.display.BitmapData = new flash.display.BitmapData(100, 40, false, 0xFF0000);
m.attachBitmap(bmp, 1);


And yup, the bmp instance never shows up.

Do you know if this handling of unloadMovie() is considered a bug or feature?

@peter, thanks for the plug :D

pixelwit
12-07-2006, 09:56 PM
I don't know if it's a bug or feature. It's mentioned in the ASDG for MX but not in the standard ASDG.

My guess is that it's probably due to some sort of "legacy" code used to avoid referencing a clip which was unloaded elsewhere.

Glad you "got it". I thought you were just ignoring me like MichaelxxOA. ;)

-PiXELWiT
http://www.pixelwit.com

badasspuppy
03-16-2007, 08:37 PM
http://www.frontend-multimedia.com/smoothImageLoader/

this is a function that you can call pretty much like loadMovie, and handles everything for you.

nahdan
05-17-2012, 07:21 AM
this is a function that you can call pretty much like loadMovie, and handles everything for you.

so im a little late to this thread.
but i was crunching late tonight trying to figure this out because my images were all jaggy.
and MAN this thing works great!! you're a lifesaver.