Sign in to follow this  

How to make bmp from raw data

This topic is 3313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings! I've been searching for quite some time on some article/open source resource that could help me in making a bmp from raw (void*) data. Just like there is D3DMXCreateTextureFromMemory() [or something similar] from microsoft-d3d, I want to accomplish the same in DDraw (windows mobile). I can easily load .bmp from file using SHLoadImageFile() provided with Pocket PC SDK, but in a scenerio where I'll have (void*) data, and if I want to make bitmap out of it (in my case, successfully copy its data to a DDraw surface),... how can I accomplish this? There was some very nice project called LodePNG here on gamedev, but, I cannot find any project that gives me above mentioned capability for bitmaps in raw form. If there's any one who can shed some light on this, I'll really appretiate it... Thanks in advance...

Share this post


Link to post
Share on other sites
Quote:
Original post by Taha Ansari
Greetings!

I've been searching for quite some time on some article/open source resource that could help me in making a bmp from raw (void*) data.

Just like there is D3DMXCreateTextureFromMemory() [or something similar] from microsoft-d3d, I want to accomplish the same in DDraw (windows mobile). I can easily load .bmp from file using SHLoadImageFile() provided with Pocket PC SDK, but in a scenerio where I'll have (void*) data, and if I want to make bitmap out of it (in my case, successfully copy its data to a DDraw surface),... how can I accomplish this?

There was some very nice project called LodePNG here on gamedev, but, I cannot find any project that gives me above mentioned capability for bitmaps in raw form.

If there's any one who can shed some light on this, I'll really appretiate it...

Thanks in advance...
I'm confused here - DirectDraw doesn't load bitmaps at all, you can just Lock() a surface and write raw pixel data to it. BMP is a file format, which has a couple of headers, then the raw bit data, possibly padded.

Are you using some utility function from another library to convert a BMP file into a DirectDraw surface? D3DXCreateTextureFromFileInMemory() takes a BMP file in memory and constructs a texture from it.

If you already have the raw bit data, you don't have to convert it to a BMP then back again, just create the surface, Lock() it, fill it, and unlock it.

Share this post


Link to post
Share on other sites
It's not too difficult to write your own code to process a .bmp file, particularly if all of your bitmaps are in a known colour format.

http://en.wikipedia.org/wiki/BMP_file_format

Alternatively, you could look into better compressing formats such as .png. I would suggest using someone else's code to load .png files, as they're much more complex.

Share this post


Link to post
Share on other sites
Quote:
Quote by Evil Steve
I'm confused here - DirectDraw doesn't load bitmaps at all, you can just Lock() a surface and write raw pixel data to it. BMP is a file format, which has a couple of headers, then the raw bit data, possibly padded.

Are you using some utility function from another library to convert a BMP file into a DirectDraw surface? D3DXCreateTextureFromFileInMemory() takes a BMP file in memory and constructs a texture from it.

If you already have the raw bit data, you don't have to convert it to a BMP then back again, just create the surface, Lock() it, fill it, and unlock it.


Yes, that is absolutely correct... allow me to elaborate my steps:

1) call SHLoadImageFile(..) function and get HBITMAP (hbitmap)
2) get BITMAP from hbitmap (bm)
2) Create a DDraw surface of bm.bmWidth x bm.bmHeight
3) Get HDC for Bitmap (hdcImage) and DDraw surface (hdc)
4) copy hdcImage to hdc

In chunks of code, this is how its done:


HBITMAP hbitmap = SHLoadImageFile( wstr );
if (hbitmap )
{
HDC hdcImage;
HDC hdc;
BITMAP bm;
GetObject(hBitmap, sizeof(bm), &bm);
//create DDraw surface of bm.bmWidth x bm.bmHeight size ... ommiting code here - assumed that surface comes into m_pSurface...

m_pSurface->Restore();

hdcImage = CreateCompatibleDC(NULL);
SelectObject(hdcImage, hBitmap);
m_pSurface->GetDC(&hdc);

BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcImage, 0, 0, SRCCOPY);
m_pSurface->ReleaseDC(hdc);
DeleteDC(hdcImage);
DeleteObject( hbitmap );
}



So far, I'm loading from file, so there is no problem here.

Now, I want the option to load from void* data as well. So, judging from above sample, I'll need to somehow convert void* data to HBITMAP form, and the rest of the steps will be handled by above code hopefully... but getting to this level is the issue here...

Quote:
...D3DXCreateTextureFromFileInMemory() takes a BMP file in memory and constructs a texture from it.

Also, as I was having problem with D3D on windows mobile, I shifted entirely to DDraw. So, D3DXCreateTextureFromFileInMemory() is not available to me... and most importantly, this function is not provided with DirectX on windows mobile SDK (to my knowledge and as far as i've seen i.e.)


Quote:

Quote by Geoffrey

It's not too difficult to write your own code to process a .bmp file, particularly if all of your bitmaps are in a known colour format.

http://en.wikipedia.org/wiki/BMP_file_format

Alternatively, you could look into better compressing formats such as .png. I would suggest using someone else's code to load .png files, as they're much more complex.

Well, if there is some routine (and I very much assume there has to be one) written by some one who's willing to share this skill, I'd happily use it... but I havn't found any thing as yet... so, I'm still searching or thinking of writing my own routine as last resort...

Share this post


Link to post
Share on other sites
... If you're starting out by calling SHLoadImageFile(), then you presumably already have an image file on disk to start out with. And the point of all of this seems to be... to create an image file on disk? What are you really trying to do?

Share this post


Link to post
Share on other sites
Quote:
Quote by Zahlman

... If you're starting out by calling SHLoadImageFile(), then you presumably already have an image file on disk to start out with. And the point of all of this seems to be... to create an image file on disk? What are you really trying to do?


Well, I had elaborated steps for my normal loading, which was not a problem, then...

Quote:
my quote

...Now, I want the option to load from void* data as well. So, judging from above sample, I'll need to somehow convert void* data to HBITMAP form, and the rest of the steps will be handled by above code hopefully... but getting to this level is the issue here...


What I meant from this statement was, I also want facility to load an image that is residing in (void*) type pointer, and points to the whole file, but in memory.

So, likewise, I want to introduce another function, whose job is to load Bitmap from memory, via:

void loadBitmapFromMemory(void* data)

Now, this data is actually whole bitmap file, but in memory...

What that meant was (recapping), I have two functions:

1) void loadBitmap(char* fileName);
2) void loadBitmapFromMemory(void* data);

Steps that I had elaborated were for (1), and now I want to implement (2) function, for which I am facing problems...

...
...
...
I'm trying another approach: I have a Bitmap wrapper open-source class that reads in binary form whole of bitmap, I'm trying to convert that so that it may be able to load from memory as well, and instead of doing fread()s to retrieve info, header, and data from file, it does memcpy() with proper bytes alignments - so far I dont have any success, but working in this direction with hope it will reveal some thing useful...

Share this post


Link to post
Share on other sites

This topic is 3313 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this