How to transform Bytes(URLLoader.data) to BitmapData when I load a png or jpg.
Use format library? I try,but failed.
I need work fine on flash and windows;
Probably you can use Loader to load images:
var loader = new openfl.display.Loader();
loader.contentLoaderInfo.addEventListener(openfl.events.Event.COMPLETE, function(_):Void {
// use (cast loader.content:Bitmap) to get Bitmap
// or use (cast loader.content:Bitmap).bitmapData to get bitmapData
});
loader.load(new openfl.net.URLRequest("http://..."), new openfl.system.LoaderContext(true));
This method works fine for all targets.
2 Likes
thanks,it ok.
If you have PNG or JPEG bytes, and need to create a BitmapData, it would be something like this:
#if !openfl_legacy
var bitmapData = BitmapData.fromBytes (bytes);
#else
var bitmapData = BitmapData.loadFromHaxeBytes (bytes);
#end
On the Flash target you would need a Loader
and loadBytes
to convert
2 Likes