Copy link to clipboard
Copied
this is my as3 function to load images from gallery to my adobe air android app . it loads picture to container , but every time , it reduce the image quality and save it on mobile ! I load one picture for 12 times and take a screenshot from that , so you can see the result in the picture. Do you have any idea what is the problem and how to fix this ?
function load_the_bg(e: MouseEvent)
{
var mediaSource:CameraRoll = new CameraRoll();
var imageLoader:Loader;
if( CameraRoll.supportsBrowseForImage )
{
mediaSource.addEventListener( MediaEvent.SELECT, imageSelected );
mediaSource.addEventListener( Event.CANCEL, browseCanceled );
mediaSource.browseForImage();
}
else
{
//show error
}
function imageSelected( event:MediaEvent )
{
mediaSource.removeEventListener( MediaEvent.SELECT, imageSelected );
mediaSource.removeEventListener( Event.CANCEL, browseCanceled );
var imagePromise:MediaPromise = event.data;
imageLoader = new Loader();
if( imagePromise.isAsync )
{
//log( "Asynchronous media promise." );
imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, imageLoaded );
imageLoader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, imageLoadFailed );
imageLoader.loadFilePromise( imagePromise );
}
else
{
//log( "Synchronous media promise." );
imageLoader.loadFilePromise( imagePromise );
var pdo : DisplayObject = ax_container.getChildByName("alpha_bg");
if (pdo)
{
ax_container.removeChild(pdo);
}
var ax_mv : Sprite = new Sprite();
ax_mv.name = "alpha_bg";
ax_mv.addChild(imageLoader);
ax_container.addChild( ax_mv );
//ax_container.alpha=.3;
}
}
function browseCanceled( event:Event )
{
mediaSource.removeEventListener( MediaEvent.SELECT, imageSelected );
mediaSource.removeEventListener( Event.CANCEL, browseCanceled );
}
function imageLoaded( event:Event )
{
imageLoader.contentLoaderInfo.removeEventListener( Event.COMPLETE, imageLoaded );
imageLoader.contentLoaderInfo.removeEventListener( IOErrorEvent.IO_ERROR, imageLoadFailed );
var pdo : DisplayObject = ax_container.getChildByName("alpha_bg");
if (pdo)
{
ax_container.removeChild(pdo);
}
var ax_mv : Sprite = new Sprite();
ax_mv.name = "alpha_bg";
ax_mv.addChild(imageLoader);
ax_container.addChild( ax_mv );
//ax_container.alpha=.3;
}
function imageLoadFailed( event:Event )
{
imageLoader.contentLoaderInfo.removeEventListener( Event.COMPLETE, imageLoaded );
imageLoader.contentLoaderInfo.removeEventListener( IOErrorEvent.IO_ERROR, imageLoadFailed );
}
}
Copy link to clipboard
Copied
Hi.
Maybe I'm missing something, but where is the code you're using to save the image back to the device?
Because it wouldn't be possible to alter an actual image file by only loading it to RAM, I guess.
Regards,
JC
Copy link to clipboard
Copied
In fact, there is not any other code! I just use this function to load a pic into the background. The function runs by tap a button. Please test my function on your device and see the result , but becarfull , select a not important pic ! I lose one of my important photos.