Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition
Accepted Solution

Issue Saving PNG from loader

[ Edited ]

Alright, I'm trying to save a png file that I've loaded using loader from the internet.

 

Here is the code:

...
public var TempImage:BitmapData;
...
var loader:Loader = new Loader();
var url:String  = new String('http://myurl.com/image.png');
...
LoadImage(); function addLoader():void{ addChild(loader); } function LoadImage():void { var urlReq:URLRequest = new URLRequest(url); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete); loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loader_err); loader.load(urlReq); addLoader(); } function loader_complete(evt:Event):void { var target_mc:Loader = evt.currentTarget.loader as Loader; var TempImage1:Bitmap = Bitmap(target_mc.content); TempImage = TempImage1.bitmapData; target_mc.x = (stWidth - stWidth) + 15; target_mc.y = (stHeight - 15) - 165; }
...
Button Code for Save button
... function SAVE(e:Event):void{ file = new FileReference(); var SaveString:String =- new String('myImage.png'); file.save(TempImage, SaveString); file.addEventListener(IOErrorEvent.IO_ERROR,saveError); file.addEventListener(Event.COMPLETE, Complete); file.addEventListener(Event.CANCEL, Complete); }
...

 

The Image (loader) Gets added to the stage successfully, the SaveString works fine, I have file system access using "access_shared", save prompt works...

 

The Issue is that The saved image (TempImage) contains no data, I've tried countless variatioins of getting the loader data into a "temp" image but without luck.

 

Any ideas?

CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting
Developer
Posts: 327
Registered: ‎12-13-2010
My Device: Bold 9900/Z10 Special Edition

Re: Issue Saving PNG from loader

I've found a solution based on my own code from a previous app.

 

I used PNGEncoder to encode the TempImage in the SAVE function prior to the actual saving.

CEO/Lead Developer - Tensioncore™ Design Studios
http://tncr.ws/ - ShortenThis!™ for Blackberry Playbook | ShortenThis!™ for BlackBerry® 10
The Periodical Toe A highly informative Table of Elements
DrawThis! A fun drawing app for the BlackBerry® PlayBook™!
http://www.tensioncore.com/ - Tensioncore™ Web Hosting