0

Is there any example which helps in generating Base64 based image from Bitmapdata? I know I have to use encode in bitmapdata, but I am not sure how to use it?

It takes (rect : flash.geom.Rectangle, compressor : flash.utils.Object, ?byteArray : flash.utils.ByteArray) : flash.utils.ByteArray;

How to fill compressor incase I want to compress using jpeg?

Also, what's the input of byteArray ? Any help?

simo
  • 23,342
  • 38
  • 121
  • 218

1 Answers1

0

There is an example in the AS3 doc of BitmapData.html#encode():

// Compress a BitmapData object as a JPEG file.
var bitmapData:BitmapData = new BitmapData(640,480,false,0x00FF00);
var byteArray:ByteArray = new ByteArray();
bitmapData.encode(new Rectangle(0,0,640,480), new flash.display.JPEGEncoderOptions(), byteArray);

To generate a Base64 String, you can use haxe.crypto.Base64 (added after 3.0.1). In OpenFL, ByteArray extends Bytes. So you may simply feed it to Base64.encode.

Andy Li
  • 5,894
  • 6
  • 37
  • 47
  • Thank you, as for AS3, byteArray is passed to encode method, by why in openFL encode returns byteArray? isn't it sent by reference already? – simo Mar 04 '14 at 06:08
  • Oh, indeed, looking at the [method signature of BitmapData.html#encode()](https://github.com/openfl/openfl-native/blob/master/flash/display/BitmapData.hx#L163) in OpenFL, seems like it always create the ByteArray for you, instead of letting you to pass a byteArray for it to write to. Definitely it _should_ follow AS3's signature. Feel free to report the issue. – Andy Li Mar 04 '14 at 06:17
  • Well... Also, the format param in OpenFL accepts only `"png"` or `"jpg"`, but not `JPEGEncoderOptions` or anything... – Andy Li Mar 04 '14 at 06:22
  • I saw that it accepts flash.utils.Object, that was the source of confusion to me, any way I've used the open source library of polygonal-gl, I think it will work for me easily – simo Mar 04 '14 at 06:24