Problem drawing bitmap with struct bmp file! Please help me! Thanks very much!

Login to reply to this topic.
Mon, 2006-02-27 03:11
Joined: 2005-06-21
Forum posts: 107
hi all !
I get a struct bmp file such as header and data. I want to view bitmap on device. please give a way for doing that. Thanks very much !
---------------------------- doctinh113114 ! --------------------

Thu, 2006-03-02 20:02
Joined: 2004-11-29
Forum posts: 1233
Re: Problem drawing bitmap with struct bmp file! Please help me
What exactly do you mean by a "struct bmp file"?

Your picture is represented by a struct with header information such as color mode, size, stride, and a pointer to a block of pixels?

Unfortunatly there is no way to handle these kinds of bitmaps in any easy way direcly with symbian classes and drawing.

What you probably want to do is convert it to a CFbsBitmap, and draw this with standard GC:s.
(you could also skip symbian drawing completly, go for direct screen access and do it quick and efficient, but I'm guessing you want it easy and few lines to write and don't care about speed)


First you need to create a CFbsBitmap with the right size and color format.

Hopefully your bitmap has a color format compatible with a format listed in TDisplayMode, then it is fairly easy, just create it with this mode, and then get the address of it with DataAddress() and fill it with pixels.

Something like this: (untested code)

Code:

//Bmp previously created with size from mystruct, and the right color format.
TSize bmpsize = bmp->SizeInPixels();

bmp->LockHeap();
TUint8* dst = (TUint8*)bmp->DataAddress();
TUint8* src = (TUint8*)mystruct.pPixels;
TInt dst_stride = CFbsBitmap::ScanLineLength(bmpsize.iWidth,bmp->DisplayMode());
TInt src_stride = mystruct.stride; //number of bytes per line in your pixel data.

for(TInt i = bmpsize.iHeight - 1; i >= 0; i--)
{
Mem::Copy(dst,src,dst_stride);
dst += dst_stride;
src += src_stride;
}

bmp->UnlockHeap();

The stride stuff is to take care of the fact that there might be extra padding bytes at the end of each CFbsBitmap scanline, to make sure the next scanline always begins on a even 32bit address. (that is, it can be anywhere between 0 and 3 bytes padding after each scanline)

After this, you have copied the pixels into a CFbsBitmap, and should throw away the original struct and the data it has allocated, since you won't need it anymore.
  • Login to reply to this topic.