Sign in to follow this  

Reading information from bitmaps

This topic is 4092 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

Help! help! help! i am trying to read the pixel information from a number of bitmaps using C++ and Directx. basicly the RGBA colour values. i have my bitmaps load in my game as sprite and have tried lockrect(ing) and unlockrect(ing) them but i get blank information back. don't think lockrect is the right way about it anyway. dose anyone know a way to get the values using directx? i only know C++ so please help in this format

Share this post


Link to post
Share on other sites
What do you mean, exaclty? You really need to elaborate on what you're trying to do/how you loaded the bitmap, but since you say you have tried using LockRect to get pixel data, I'm going to assume you have used a function like D3DXCreateTextureFromFile to load the bitmap in and not your own code, and now want to get the actual pixel color component data. Well I just tried LockRect and I was able to get the data that way. I've been using OpenGL and have just fairly recently begun playing around with Direct3D. But from what I can tell, pixel data in D3D texture objects have to be represented by 32-bit values. Even if an image doesn't contain an alpha channel, the pixel data in the texture object will still be represented by 32-bit numbers. The 8 highest-order bits, which would be the alpha component if the image had an alpha channel, will just be set to zero. If you have been trying to read the pixel data using LockRect like this into an array of BYTEs or something, your problem could be that you didn't anticipate these extra 8 bits after the BGR of every pixel.

Also, to get the width and height of a bitmap, you could call the GetLevelDesc member function of the IDirect3DTexture9 objects with 0 for the level.

I hope that was what you wanted to know. But you didn't make yourself extremely clear as to what your problem was, so I may have just rambled on for nothing =).

EDIT: Alternatively, you could just load bitmaps in with your own code and create a texture from it with IDirect3DDevice9::CreateTexture() or D3DXCreateTexture(). Wotsit's Format is a great site for finding file formats, if you don't know the bitmap format.

Share this post


Link to post
Share on other sites
I'm with K A Z E - we need more technical information if we're to help you. You say you've tried to get the data which is a good start, but how did you use LockRect? As has been pointed out, it is the correct way to do it so you might be on the right track just doing something slightly wrong.

Quote:
But from what I can tell, pixel data in D3D texture objects have to be represented by 32-bit values.
No, this isn't the case. Look up the D3DFORMAT enumeration for all the possible values. D3DX tends to pick 32bit ARGB values as its a nice convenient/close match, but in general there is no requirement for that format...

Also, look at the FAQ:
D3D #21: How to interpret the data returned by a Lock() operation
D3D #23: Texture creating/loading enumeration and checking

Jack

Share this post


Link to post
Share on other sites
Sorry about the lack of information. i have not posted before.

Besicly i have created a game with a number of sprites loaded in as bitmaps using D3DXCreateTextureFromFileEx to load them the format i have set the sprites to is D3DFMT_A8R8G8B8.

The sprites display fine on the screen. but now i am working on colition detection for my sprites. I have bounding boxes and they work fine but i also need pixel by pixel detection.

This is were the colour values will be used.

i am trying to make an array of bool(s) using the colour values from the bitmaps. 1 bool in the array represents 1 pixel in my bitmaps. a colour black in the bitmap is set to 0 in the array as this is the transparent colour. 0 in the array represents not hit. all other colours in the bitmaps is represented in the array with 1. i.e. hit the object.

The big problem i have is if i couldn't make the array using the colour values from my bitmaps, i will have to make the array by hand. the game has 20+ 2048x2048 bitmaps so as u can see a lot of work if done by hand. don't realy want to do that

Share this post


Link to post
Share on other sites

This topic is 4092 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