Please help with Bitmap issue. I have screen shots!?!

by chris harper » Fri, 07 Jan 2011 04:53:11 GMT


Sponsored Links
 Kostya (or anyone else)

Ok. In TRYING to write out a  ANDROID Bitmap to a windows .bmp file.
I am very close but there is something that is still off because my image
doesn't look right (as in the screen shot below).

Here is how I am writing out to the file:

cache - is the Android Bitmap file which I want to write out to a .bmp file.

It is  set to:  Bitmap.Config.ARGB_8888

                           //Get the Bitmap height, width, and put the data
into a byte array (bytesar)

                            byte[]   bytesar   = null;
                            ByteBuffer  dst   = null;

                            int height = cache.getHeight();
                            int width = cache.getWidth();
                            int bmSize = cache.getRowBytes() * height;

                           dst = ByteBuffer.allocate(bmSize);

                           bytesar = new byte[bmSize];


                            dst.position(0);
                            cache.copyPixelsToBuffer(dst);

                            dst.position(0);
                            dst.get(bytesar);

                           //I then write out the bytesar byte array AFTER I
write out the BMP header.


     The settings in the header are:

     private byte bitmapInfoHeader [] = new byte [40]; - Header size is 40
    private int biSize = BITMAPINFOHEADER_SIZE;
    private int biWidth = width                  //width of Bitmap
    private int biHeight = height               //height of Bitmap
    private int biPlanes = 1;
    private int biBitCount = 32;               //The bite count is 32
    private int biCompression = 0;

     size is computed by:
     int pad = (4 - ((width * 3) % 4)) * height;
     biSizeImage = ((width * height) * 3) + pad;

    private int biSizeImage
    private int biXPelsPerMeter = 0x0;
    private int biYPelsPerMeter = 0x0;
    private int biClrUsed = 0;
    private int biClrImportant = 0;

It's very close because here is what it looks like when I write out the .bmp
file.
As you can see it's upside down and the colors are off:
 http://i1092.photobucket.com/albums/i409/ch39336688/test-2.jpg 

In the same block of code I write out using the Android lib to make sure
that my image is good via the code:
FileOutputStream out = new FileOutputStream("test.png");
 cache.compress(Bitmap.
CompressFormat.PNG, 90, out);

And here is how that comes out (which is how I want):
 http://i1092.photobucket.com/albums/i409/ch39336688/test.png 

Again I don't just want to use compress to write out my images because I
have a lot of images and it kills my performance. So I want to stream the
images out to a .bmp file is what my overall goal is. Someplace in my .bmp
header I have something wrong I think.

Any help on what anyone thinks my issue is would be a great help. Thank you

-Chris

-- 



Re: Please help with Bitmap issue. I have screen shots!?!

by Kostya Vasilyev » Fri, 07 Jan 2011 05:12:31 GMT


 hris,

First off, Windows bitmap are stored upside-down:

http://en.wikipedia.org/wiki/BMP_file_format#Pixel_Array_.28bitmap_data.29

The Pixel Array is a block of 32-bit DWORDs, that describes the image
pixel by pixel. Normally pixels are stored "upside-down" with respect
to normal image raster scan order, starting in the lower left corner,
going from left to right, and then row by row from the bottom to the
top of the image.[1]


I *think* you can indicate top-down order by setting height to a
negative value (in the file header).


Secondly, the color problem - 32-bit per pixel Windows bitmaps use BGRx
data format, blue-green-red, then one byte is ignored.


Your input image is ARGB, so red and blue are switched around.

Since you indicated that you'll be processing these images further, you
could handle both issues in your server code. Or you could handle them
on the phone, changing byte order around isn't going to be as
time-consuming as compression.


-- Kostya

06.01.2011 23:53, chris harper ?????:

Kostya (or anyone else)

Ok. In TRYING to write out a ANDROID Bitmap to a windows .bmp file.
I am very close but there is something that is still off because my
image doesn't look right (as in the screen shot below).


Here is how I am writing out to the file:

cache - is the Android Bitmap file which I want to write out to a .bmp
file.

It is set to: Bitmap.Config.ARGB_8888

//Get the Bitmap height, width, and put the
data into a byte array (bytesar)


byte[] bytesar = null;
ByteBuffer dst = null;

int height = cache.getHeight();
int width = cache.getWidth();
int bmSize = cache.getRowBytes() * height;

dst = ByteBuffer.allocate(bmSize);

bytesar = new byte[bmSize];


dst.position(0);
cache.copyPixelsToBuffer(dst);

dst.position(0);
dst.get(bytesar);

//I then write out the bytesar byte array
AFTER I write out the BMP header.



The settings in the header are:

private byte bitmapInfoHeader [] = new byte [40]; - Header size is 40
private int biSize = BITMAPINFOHEADER_SIZE;
private int biWidth = width //width of Bitmap
private int biHeight = height //height of Bitmap
private int biPlanes = 1;
private int biBitCount = 32; //The bite count is 32
private int biCompression = 0;

size is computed by:
int pad = (4 - ((width * 3) % 4)) * height;
biSizeImage = ((width * height) * 3) + pad;

private int biSizeImage
private int biXPelsPerMeter = 0x0;
private int biYPelsPerMeter = 0x0;
private int biClrUsed = 0;
private int biClrImportant = 0;

It's very close because here is what it


Sponsored Links


Re: Please help with Bitmap issue. I have screen shots!?!

by chris harper » Fri, 07 Jan 2011 06:13:02 GMT


 hank you again Kostya

I will research based on what you told me and let you know if I get it to
work.

-Chris

On Thu, Jan 6, 2011 at 2:12 PM, Kostya Vasilyev <kmans...@gmail.com> wrote:


--



Other Threads

1. PORTING OF NEW OMX_CORE WITH STAGEFRIGHT

I am trying to integrate a omx core to the android2.2 stagefright, but
i am facing some problems while creating the shared libraries of my
core. It seems some path setting in the android.mk files is not
proper. I need help in the path settings in the make file so that it
includes the make files from my omx_core.

Does anyone know how to write an android.mk file??

-- 

2. Mod: Paging ID-Android Jogja

Bagi rekan-rekan yang punya waktu luang, bisa menyempatkan hadir di acara:

Android Roadshow  "Sosialisasi Kompetisi Aplikasi Android"

Hari/Tgl         : Jumat, 25 Februari 2011
Waktu           : 13.30 - Selesai
Tempat         : University Center UGM, UGM Yogyakarta

Narsum        : Kominfo, AH, Perwakilan Kampus UGM

-- 
Salam,


Agus Hamonangan

Founder 

3. [WTAsk] Aplikasi presentasi

4. Output to projector or connected display from Android tablet and/or phone?

5. Android soundpool stop sequence of sounds

6. ListView adapter bug?; notify changed does nothing.

7. TextView adjusts, ImageView stays static when keyboard pops up - How To?