Skip to main content
Participating Frequently
December 5, 2011
Question

How to convert Bitmap to FREBitmapData ....??

  • December 5, 2011
  • 2 replies
  • 1452 views

Hello, all..

How to convert Bitmap to FREBitmapData ....??

my code is below..

---------------------------------------------------------------------------------------------------------------------------------

Bitmap bitmap // <= bitmap image

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

bitmap.compress(CompressFormat.PNG, 100, outputStream);

byte[] byteArray = outputStream.toByteArray();

int width = bitmap.getWidth();

int height = bitmap.getHeight();

FREBitmapData bitmapData = FREBitmapData.newBitmapData(width, height, true, byteArray);  <== Error :

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

12-05 20:34:45.773: W/System.err(9051): java.lang.IllegalArgumentException: fillColor has wrong length

12-05 20:34:45.773: W/System.err(9051):           at com.adobe.fre.FREBitmapData.newBitmapData(FREBitmapData.java:66)

12-05 20:34:45.773: W/System.err(9051):           at air.com.sec.flash.extension.library.bitmap.UriLoader$2.call(UriLoader.java:284)

12-05 20:34:45.773: W/System.err(9051):           at com.adobe.air.customHandler.callTimeoutFunction(Native Method)

12-05 20:34:45.773: W/System.err(9051):           at com.adobe.air.customHandler.callTimeoutFunction(Native Method)

12-05 20:34:45.773: W/System.err(9051):           at com.adobe.air.customHandler.handleMessage(customHandler.java:18)

12-05 20:34:45.773: W/System.err(9051):           at android.os.Handler.dispatchMessage(Handler.java:99)

12-05 20:34:45.773: W/System.err(9051):           at android.os.Looper.loop(Looper.java:130)

12-05 20:34:45.773: W/System.err(9051):           at android.app.ActivityThread.main(ActivityThread.java:3691)

12-05 20:34:45.773: W/System.err(9051):           at java.lang.reflect.Method.invokeNative(Native Method)

12-05 20:34:45.773: W/System.err(9051):           at java.lang.reflect.Method.invoke(Method.java:507)

12-05 20:34:45.773: W/System.err(9051):           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)

12-05 20:34:45.773: W/System.err(9051):           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)

12-05 20:34:45.773: W/System.err(9051):           at dalvik.system.NativeStart.main(Native Method)

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

why wrong length??

How to convert Bitmap to FREBitmapData ??

in sample of the adobe, an same error occur..

http://help.adobe.com/en_US/air/extensions/WS11d1def534ea1be0-67da1176132a8869db6-7ffe.html

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Byte[] fillColor = {0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf};

FREBitmapData bitmap = FREBitmapData.newBitmapData( 320, 200, true, fillColor );

int lineStride = bitmap.getLineStride32();

bitmap.acquire();

ByteBuffer pixels = bitmap.getBits();

pixels.position( lineStride * 3 );

//do something with the image data

bitmap.release();

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This topic has been closed for replies.

2 replies

January 8, 2016

Im at work at the moment, so I can't test this yet but here are some suggestions I have. The last argument in the FREBitmapData.newBitmapData() method call is the "fillColor", so it is expecting a solid color value. Not the entire byte data value of the Bitmap. I found one example that used the following value for the fillColor as opposed to what was in the Adobe example:

byte[] fillColor = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };// solid white, no transparency

Bitmap bitmap // <= bitmap image

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

bitmap.compress(CompressFormat.PNG, 100, outputStream);

byte[] byteArray = outputStream.toByteArray();

int width = bitmap.getWidth();

int height = bitmap.getHeight();

FREBitmapData bitmapData = FREBitmapData.newBitmapData(width, height, true, fillColor);

bitmapData.acquire();

ByteBuffer buffer = bitmapData.getBits();

buffer.put(byteArray);

bitmapData.release();

I don't entirely understand why/how it works, but when dealing with FREByteArray, you must call acquire() on it, add in data to a ByteBuffer using put(), and then once that is done, call release(). Somehow manipulating a ByteBuffer object in between the acquire() and release() puts the data into the FREByteArray. Since there is also an acquire() and release() method on the FREBitmapData, Im going to take a guess at the moment that it is the same approach.

There is also an invalidateRect() method on FREBitmapData that may need to be called either before or after release(). Since you are just trying to get data from Java to Flash and not actually update a visual on the Java side, you may not need it. In this example, I would assume the way you call it would be (again, if needed):

bitmapData.invalidateRect(0, 0, width, height);// width & height is referencing your above int values.

Let me know if this helped or if I (sadly) just crushed your dreams of getting it to work.

geekmisan
Participant
January 8, 2016

same problems,,help!!!