ianharrigan

Untitled

Jan 15th, 2016
529
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     private function getImageFromHaxeResource(resourceId:String, callback:String->ImageInfo->Void) {
  2.         var bytes:Bytes = Resource.getBytes(resourceId);
  3.        
  4.         #if html
  5.        
  6.         var image = Browser.document.createImageElement();
  7.         image.onload = function(e) {
  8.             var t = System.renderer.createTextureFromImage(image);
  9.             var imageInfo:ImageInfo = {
  10.                 width: t.width,
  11.                 height: t.height,
  12.                 data: t
  13.             }
  14.             callback(resourceId, imageInfo);
  15.            
  16.         }
  17.         var base64:String = haxe.crypto.Base64.encode(bytes);
  18.         image.src = "data:image/png;base64," + base64;
  19.        
  20.         #else
  21.        
  22.         var ba:ByteArray = ByteConverter.fromHaxeBytes(bytes);
  23.         var loader:Loader = new Loader();
  24.         loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e) {
  25.             if (loader.content != null) {
  26.                 var bmpData = cast(loader.content, Bitmap).bitmapData;
  27.                 var t = System.renderer.createTextureFromImage(bmpData);
  28.                 var imageInfo:ImageInfo = {
  29.                     width: t.width,
  30.                     height: t.height,
  31.                     data: t
  32.                 }
  33.                 callback(resourceId, imageInfo);
  34.                
  35.             }
  36.         });
  37.         loader.loadBytes(ba);
  38.        
  39.         #end
  40.     }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×