Sign in to follow this  
Raeldor

Texture From GDI Bitmap Object

Recommended Posts

Raeldor    254
Is there an easy way to create a direct3d texture object from an in-memory gdi+ bitmap? I can't see a D3DX helper function for it. Failing that, is there an easy way to directly set pixels on a direct3d texture? Thanks

Share this post


Link to post
Share on other sites
Raeldor    254
I found this snippet of code which looks good. Quick question though... does the pitch represent the number of bytes in a row of the returned rectangle?

Thanks


LPDIRECT3DTEXTURE9 texture;
...
...
D3DXCreateTextureFromFileEx(.., 0, D3DFMT_L8, D3DPOOL_SCRATCH, .., &texture );
...
...
D3DLOCKED_RECT data;
HRESULT hr;
hr = texture->LockRect( 0, &data, NULL, D3DLOCK_READONLY );
if (FAILED(hr))
{
// error handling goes here
// (locking something in the scratch pool
// usually shouldn't fail anyway)
}
...
...
// now have access to the raw data in the texture surface.
...
// cast the void pointer to the size of one of our D3DFMT_L8 pixels
// so that the compiler knows the size of an item of data
// this allows us to do pointer arithmetic on the surface
BYTE* bits = (BYTE *)data.pBits;
...
// access the pixel at x=10, y=20:
int offset = ((data.Pitch/sizeof(BYTE)) * 20) + 10;

BYTE pixel = bits[offset];
...
texture->UnlockRect( 0 );

Share this post


Link to post
Share on other sites

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