Chris,
Let's clear some terminology first. You don't have "Android bitmaps" -
you're writing data out in your own, uncompressed, format.
Reading this format should be pretty easy, just reverse the code below.
For compressing to PNG outside Android, try this:
http://code.google.com/p/javapng/
or Google for "Java PNG", there are other libraries as well.
You could also write out your bitmap in Windows .BMP format - it would
be just as fast, since it's uncompressed, you just need to add some headers.
http://en.wikipedia.org/wiki/BMP_file_format#Bitmap_File_Header
You'd then be able to view the file outside Android with pretty much any
graphics file viewer, and do the conversion using any graphics
manipulation program (FastStone, IrfanView, Gimp, Photoshop, etc.)
-- 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