PS - there is also this library from Sun / Oracle:

http://java.sun.com/products/java-media/jai/iio.html

which can save to PNG in one line of code:

http://java.sun.com/products/java-media/jai/forDevelopers/jaifaq.html#save

-- Kostya

05.01.2011 20:02, chris harper пишет:
This a Bitmap question.

Given an Android Bitmap which has been written to file I want to read the Android BitMap from the file and convert it to a PNG OUTSIDE of Android (via a regular java program).


Here is how I am writing out the Bitmap to a file:
screenShot - is a Bitmap

//Get Bitmap information
int height = screenShot.getHeight();
int width = screenShot.getWidth();
int bmSize = screenShot.getRowBytes() * height;

//Write the Bitmap to a byte array
ByteBuffer dst = ByteBuffer.allocate(bmSize);
byte bytesar = new byte[bmSize];
dst.position(0);
screenShot.copyPixelsToBuffer(dst);
dst.position(0);
dst.get(bytesar);

//Write it to a file
//I write out the height, width and size before the Bitmap data so I know what the Bitmap dimensions are when reading back in
final int BUFFSIZE = 32 * 1024;
final int streamBuffSizeInBytes = ( ( BUFFSIZE * 2 * 75 / 100 ) + 8 ) / 16 * 16;
File f = new File("buffer");
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(filename), streamBuffSizeInBytes);
out = new ObjectOutputStream(bout);
out.writeInt(height);
out.writeInt(width);
out.writeInt(bmSize);
out.write(bytesar, 0, bytesar.length);


Now I realize that I can just write out the Bitmap in the from of a PNG via:

screenShot.compress(Bitmap.CompressFormat.PNG, 90, output);

The issue here is performance. I have a lot of images that I need to write out and this command is very expensive, time consuming and kills my performance:
screenShot.compress(Bitmap.CompressFormat.PNG, 90, output);

Where if I just grab the Bitmap and write it out using a BufferedOutputStream (as above) it is very fast and I can write many images to a file (or socket) very quickly. Then OUTSIDE of Android do the work to convert the Bitmap's to PNG file's.

So the question I have is how can I read the Bitmap from a file OUTSIDE of Android and convert it to a PNG? Like I said I send the dimensions of the image before the image itself so I can read it back in via:
out.writeInt(height);
out.writeInt(width);
out.writeInt(bmSize);
out.write(bytesar, 0, bytesar.length);

Essentially I need to do the Android command OUTSIDE of Android:
BitMap.compress(Bitmap.CompressFormat.PNG, 90, output);

Or find the Java command which does the same thing.
Or how does Java "see" an Android Bitmap when I read it back in?
I read where ByteBuffer is the same as Bitmap but in my tests (via writing out the Bitmap in Android and reading it in as a ByteBuffer in java) that does not appear to be the case.

Any help would be wonderful.

Thank you
-Chris





--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to