07-22-2008 02:45 PM
Quote from the previous forum:
|Anyone got any hints or code snippet to help me convert a Bitmap to byte? (not the other way round).|
07-22-2008 05:12 PM - edited 07-22-2008 05:14 PM
Ok, folks. I ported a PNGEncoder to BlackBerry and am making it available here. What this will do is convert a Bitmap to a PNG and then return a byte array of the resulting PNG, which should be generally useful since that's pretty much the lingua franca of midp. Source is located at my Mobiyana site.
Here's how to use it:
PNGEncoder encoder = new PNGEncoder(bitmap, true);
byte imageBytes = encoder.encode(true);
if you then want an EncodedImage do this:
EncodedImage fullImage = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length);
07-23-2008 09:56 AM
08-27-2008 05:38 AM
I am resizing the bitmap using getARGB method. I want the byte data from resized bitmap?
How can I do that? I have tried the way explained in forums but no success.
I am not able to generate the bitmap from the data which is converted from int to byte.
Can anybody tell how to do it?
10-17-2008 09:48 AM
I have used the following but it is is very slow. I am currently working to speed this up.
DataBuffer db = new DataBuffer();
width = Display.getWidth();
height = Display.getHeight();
Bitmap testBitmap = new Bitmap(width, height);
Display.screenshot(testBitmap, 0, 0, width, height);
int rgbdata = new int[width*height];
testBitmap.getARGB(rgbdata, 0, width, 0, 0, width, height); // <<<<<<<<< int array
for (int i = 0; i < (width * height); i++) // <<<<<<<<< move to byte array
10-21-2008 11:43 AM
Does anyone have any ideas to quickly transfer a integer array to a byte array?
I need to transfer the bitmap information across the USB connection. The USBPort class requires a byte array. I also attempted to compress the image but the ZLibOutputStream class also requires a byte array.
10-21-2008 12:20 PM
I used to work at EyeWonder and wrote a java applet for streaming audio and video to browsers ( mostly for ad delivery
until Flash audio support was better). Anyway, I remember getting annoyed that in some cases the screen updates/manipulations
with the int<->byte conversions were on the top of the profiler list which is quite a trick when you have a codec and a lot of other stuff going on. AFAIK, the brute force shift and mask approach is still quite reasonable. Anyone who tries to serialize an int needs an endian
spec etc. I did find a RIM BitSet class and was hoping they had something like a ByteStream that loads from int but nothing obvious.
Offhand I wouldn't bet that a per-int call to DataBuffer would be any faster than your own hard coded shifting logic.
05-11-2009 06:23 AM
I used the PNGEncoder in JDE 4.2.1. I wanted to send the Bitmap as email. So i converted Bitmap to Byte Array using PNGEncoder.After composing the Message i am passing the Message object as argument to Invoke Email Client. Now when user clicks on send, i get null pointer exception. One more thing i observed was the size of attachment shown in email client after encoding increases (Actual size was 80kb, After attachment 700+ kb). Also i wrote a small program to call Email Client by hardcoding the attachment by not using PNGEncoder, and i don't get any exception here.
Observation on JDE 4.7 - PNGEncoder was working fine. But if i send email, come back again compose Message and invoke email client. If i repeat this. I again get Null Pointer Exception. (The behaviour is inconsistant). Then i used JPEGEncoder, its working fine. But it is available 4.6 onwards.
Anyone has faced similar issue? Please provide your opinion.
05-14-2009 02:20 AM