Reputation: 15
we are loading the images via xml in a tile visualizer application, the image doesn't look smooth at some part and lines inside the tile image looks jagged. here is the image link [1]: http://postimg.org/image/h4schoiub/"![enter image description here][1]
Please note that i am not an flash actionscript expert
And here is my image handler code
package com.listplugin
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
import flash.utils.getDefinitionByName;
//Use of class
//l2.img.setSource("gear.png");
//l2.img.setDimension(199,87,true);
//l2.img.startLoad();
/**
* ...
* @author Mike 2011
*/
public class ImageHandler extends MovieClip
{
private var url:String;
private var isExternal:Boolean;
private var img;
private var w:Number;
private var h:Number;
private var maintainRatio:Boolean;
private var m_owner:MovieClip;
private var m_func:MovieClip;
private var center:Boolean;
private var childs:Array;
private var isSmooth:Boolean;
public function ImageHandler()
{
}
public function setSource(p_url:String)
{
isSmooth = false;
if (childs)
{
for (var i = 0; i < childs.length; i++)
{
removeChild(childs[i]);
}
}
childs = new Array();
center = true;
url = p_url;
isExternal = true;
if (url.indexOf(".jpg") == -1 && url.indexOf(".gif") == -1 && url.indexOf(".png") == -1 && url.indexOf(".jpeg") == -1 && url.indexOf(".jpeg") == -1)
{
isExternal = false;
}
}
public function startLoad()
{
if (isExternal == true)
{
loadExternalImage();
}
else
{
var ClassReference:Class = getDefinitionByName( url ) as Class;
img = new ClassReference();
addImage();
if (m_func)
m_func.imageloaded();
}
}
public function setDimension(p_width:Number, p_height:Number, p_maintainratio)
{
w = p_width;
h = p_height;
maintainRatio = p_maintainratio;
}
public function makeSmooth(p_flag:Boolean)
{
isSmooth = p_flag;
}
private function loadExternalImage()
{
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest(url);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
private function onCompleteHandler(loadEvent:Event)
{
img = loadEvent.currentTarget.content;
addImage();
}
public function callback(p_owner:MovieClip)
{
m_func = p_owner;
}
private function addImage()
{
if (w == 0) w = img.width;
if (h == 0) h = img.height;
if (maintainRatio == true)
{
var hgap = img.width - w;
var vgap = img.height - h;
if (img.height > img.width)
{
img.height = h;
img.scaleX = img.scaleY;
if (img.width > w)
{
img.width = w;
img.scaleY = img.scaleX;
}
}
else
{
img.width = w;
img.scaleY = img.scaleX;
if (img.height > h)
{
img.height = h;
img.scaleX = img.scaleY;
}
}
if (center==true)
{
img.x = (w - img.width) / 2;
img.y = (h - img.height) / 2;
}
}
else
{
img.width = w;
img.height = h;
}
addChildAt(img, 0);
childs.push(img);
if (m_func)
m_func.imageloaded();
}
public function makeCenter(p_flag:Boolean)
{
center = p_flag;
}
private function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
}
}
}
Upvotes: 0
Views: 203
Reputation:
That's because you're scaling the image.
Loader will return a Bitmap Object, which has a property called smoothing.
Essentially you should do this
var img:Bitmap;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.Complete, onComplete);
loader.load(new URLRequest(pathToTheImage));
function onComplete(e:Event):void{
img = e.content as Bitmap;
img.smoothing = true;
//then scale it
}
Take a look at the AS3 Documentation for Bitmap
Upvotes: 1