Sorry for the dumb question, but I've been reading from platform SDK for hours but still cannot solve this problem: I have an array of RGB values and I want to create a 24-bit bitmap. Then, I want to do the reverse: from a 24-bit bitmap I want to get an array of RGB values. Every way I tried I get some error: is there any example
Thank you,
Ignazio

How to use bitmaps
dinsdale
Ignazio
elias_adum
To read the data I tried to directly access the biData field of BITMAP structure returned by GetObject (always finding it NULL) or use GetDIBits, but I always get a return value of 0.
To write a new bitmap I tried CreateBitmap, CreateDIBitmap or CreateCompatibleBitmap, apparently succeding but having an error when, returning in managed environment, I try and use the HBITMAP for Bitmap::FromHandle.
In pratictice, I need an example or better documentation than the PSDK one.
Thank you,
Ignazio
J. Ho
There is 2 way to create and use texture BMP
The hard way is to use the GDI...it's also the old way :-)
The much more easier way is to use your DX to create a file and read the Bits
First, a comment on your GDI attempt :-)
The BITMAP structure is empty by default and you have to create the space for it
It's a structure not a real object so you need to open the space with malloc
And then load the data by reading a BMP file bits from a file...and it's a pain
CreateDiBitmap (device independant = DI) or CreateBitmap could work
But it's also empty and you need to fill it as you know
And then there is the object you need to load in the GDI DC to use...
But there is a ''simpler'' way to do this now
D3DXCreateTexture() for new one OR
D3DXCreateTextureFromFile() to read a BMP into a Texture
You can also save the BMP to a file with
D3DXSaveTextureToFile()
Once you have this Texture you can access the bits by Locking a Rectangle
Something like :
D3DXTexture8 *pTexture;
D3DXCreateTextureFromFile("MyBmp.Bmp",...,&pTexture)
pTexture->LockRect(...,&pRect);
pRect structure include a pBits and a...pitch
To read the Bmp Bits you really need to use this pitch...
To read the Bit at x,y you could use something like this:
val = pRect->pBits[x+y*pitch];
You can store value in it also
pRect->pBits[x+y*pitch] = val;
Then you Unlock the Texture Rect...
pTexture->Unlock();
And you use your texture new bits...or save in in a file
The best part is this work with all format, like jpg, tga etc...
Last problem is that the call for each bit is not as simple has I wrote above
In reality depending on the format you choose you will in fact have 3 or 4 value
For each bits...one for each RGB value or RGBA value...
So the 4 bytes of the pBits can represent R, G, B and A value
This combine to ONE pixel of a specific color...
Something like this (not the actual final code...just a sample)
valR = pRect->pBits[x+y*pitch+0];
valG = pRect->pBits[x+y*pitch+1];
valB = pRect->pBits[x+y*pitch+2];
valA = pRect->pBits[x+y*pitch+3];
x=x+4;
MyPixel = COLORRGB(valR,valG,valB,valA)
http://msdn.microsoft.com/archive/default.asp url=/archive/en-us/directx9_c_dec_2004/directx/graphics/reference/d3dx/functions/texture/d3dxcreatetexture.asp
http://msdn.microsoft.com/archive/default.asp url=/archive/en-us/directx9_c_dec_2004/directx/graphics/reference/d3d/interfaces/idirect3dtexture9/_idirect3dtexture9.asp
http://msdn.microsoft.com/archive/default.asp url=/archive/en-us/directx9_c_dec_2004/directx/graphics/reference/d3d/interfaces/idirect3dtexture9/LockRect.asp
http://msdn.microsoft.com/archive/default.asp url=/archive/en-us/directx9_c_dec_2004/directx/graphics/reference/d3d/structures/d3dlocked_rect.asp
Airex
Its fairly slow but have you tried Bitmap.GetPixel (http://msdn2.microsoft.com/wbey6xyz(en-US,VS.80).aspx)
Otherwise, what other methods are you trying