Jump to content
  • Advertisement
Sign in to follow this  
Dark_Light

Texture - Byte[] - Texture

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

Anyone know a function to get a texture into a byte[] without messing around with lots of for loops. I would also need a way to get the byte[] back into the texture! If this cant be done is there a way to get the length of a texture in bytes! NOTE this will all have to work regardless of texture format. Thanks

Share this post


Link to post
Share on other sites
Advertisement
I don't know about C++, but at in Managed DirectX the Texture class has a GetPrivateData() method that returns a byte[], and a SetPrivateData() method that takes one. The documentation for GetPrivateData says it "Copies the private data associated with a resource to a buffer" - sounds about right to me.

Hope that was what you're looking for.

Share this post


Link to post
Share on other sites
I just learned this from another post (thanks to the OP of this code)

D3DLOCKED_RECT data;
HRESULT hr;

hr = texture->LockRect(0, &data, NULL, D3DLOCK_READONLY);
if FAILED(hr)
return;

BYTE* bits = (BYTE *)data.pBits;
//if you want a specific x,y offset of the texture, use:
//int offset = ((data.Pitch/sizeof(BYTE)) * y) + x;

texture->UnlockRect(0);


You can both get data and manipulate data this way.

Share this post


Link to post
Share on other sites
visage, Thats ok for getting the data into an array but you have no idea how long the data array is.

_Flecko sounds good but not sure what data is in there. I dont see how that data can be in there if its not been locked?

I cant try anything until i get home.

Thanks

Share this post


Link to post
Share on other sites
Quote:
Original post by Dark_Light
visage, Thats ok for getting the data into an array but you have no idea how long the data array is.

Well, if you know the texture format and the texture width/height, you should know the size as well.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!