Loader changes the pixel value after loading as bitmap
hi all,
my aim load 2 images , compare color information pixel pixel. purpose used "flash.display.loader" class load images, , once load completes i'll typecast loaded content bitmap object (loaderobj.content bitmap). i'll bitmapdata bitmap of both images , compare pixels.
now problem color information of original image , loaded bitmap different. example color value of pixels of attached image image1.jpg 0xdddddd complete 1366x768. , same image when loaded bitmap color value of pixels different original value (for pixels only, not pixels different).
i’ve given source code , sample images.
please can me out how resolve issue?
<?xml version="1.0" encoding="utf-8"?>
<s:windowedapplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="1376" height="800"
showstatusbar="false">
<fx:declarations>
<!-- place non-visual elements (e.g., services, value objects) here -->
</fx:declarations>
<fx:script>
<![cdata[
private function loadbtn_clickhandler():void{
var file:file = new file(file.desktopdirectory.nativepath);
file.addeventlistener(event.select, onfileselectionhandler);
file.browseforopen("open image",[new filefilter("images", "*.jpg;*.gif;*.png;*.jpeg")]);
}
private function onfileselectionhandler(ev:event):void{
var loadedfilepath:string = (ev.target file).nativepath;
loadimageasbitmap(loadedfilepath);
}
/* load image bitmap using loader */
private function loadimageasbitmap(url:string):void{
var loader:loader = new loader();
// load content bitmap
loader.contentloaderinfo.addeventlistener(event.complete, oncontentloadcomplete);
loader.contentloaderinfo.addeventlistener(ioerrorevent.io_error, oncontentloadfail);
loader.load(new urlrequest(url));
}
private function oncontentloadcomplete(ev:event):void{
var loaderinfo:loaderinfo = ev.target loaderinfo;
var bitmap:bitmap = loaderinfo.content bitmap;
printpixelvalue(bitmap.bitmapdata);
container_id.addchild(bitmap);
}
private function oncontentloadfail(ioe:ioerrorevent):void{
trace("image load failed");
}
private function printpixelvalue(bmdata:bitmapdata):void{
var initpixelvalue:number = -1;
//for (var counti:int = 0; counti < bmdata.height; counti++) {
var counti:int = 1;
(var countj:int = 0; countj < bmdata.width; countj++) {
var pixelvalue:number = bmdata.getpixel32(countj, counti);
if(pixelvalue != initpixelvalue){
initpixelvalue = pixelvalue;
// print pixel value 1 row
trace("pixel value @ " + counti + "x" + countj + " is: " + pixelvalue);
}
}
trace("pixel value @ " + counti + "x" + countj + " is: " + pixelvalue);
//}
}
]]>
</fx:script>
<s:button id="loadbtn_id" label="load!" click="loadbtn_clickhandler()"
x="5" y="5" height="20"/>
<mx:uicomponent id="container_id" x="5" y="30" width="1366" height="768"/>
</s:windowedapplication>
sample image:
thanks all,
updating sdk 4.6.0 fixed issue
More discussions in Flex (Read Only)
adobe

Comments
Post a Comment