Jump to content
  • Advertisement
Sign in to follow this  
Guilherme Amorim

Loading D2D1Bitmap from raw image file in memory

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

Hello, I'm new in the forums, so pleased to meet you!

I've been working the last weeks on a library for game development to help me with simple and common functions. One of them is compression and decompression of game resources, such as sprites and textures. I extract them on demand into memory. But I got myself stuck with this, I can't find a way to convert it to a D2D1Bitmap, the methods I find need to pass a URI, and I don't have it, I only have the binary data of a PNG encoded image.

Is there a way to use the data directly from memory instead of loading it from hdd?

Share this post


Link to post
Share on other sites
Advertisement

The bitmap creation function has a parameter "pSrcData", which you can use to initialize the bitmap contents from memory.

http://msdn.microsoft.com/en-us/library/windows/desktop/dd371800(v=vs.85).aspx

 

If you already have a bitmap allocated and want to set its memory, use the following:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd371155(v=vs.85).aspx

 

Note that the creation is potentially expensive, so you will want to use the CopyFromMemory method if you update the bitmap often.

 

EDIT: You will need to decode the PNG to raw pixels before doing these. For this, you may want to use the IWICBitmapDecoder implementations:

http://msdn.microsoft.com/en-us/library/windows/desktop/ee690086(v=vs.85).aspx

 

That said, you can use any decoder, as long as you get the raw pixel array in the end.

Edited by Nik02

Share this post


Link to post
Share on other sites

Thanks,
Correct me if I'm wrong, but a pseudo code for that would be something like this :

Create a stream from my stored image
Initialize a decoder passing the stream
Get Frame 0 from decode

Pass to bitmap creation (I can guess that the decoder can produce the dimensions) and keep bitmap pointer to use it to draw

Use this guy: http://msdn.microsoft.com/en-us/library/windows/desktop/dd371797%28v=vs.85%29.aspx


Is That it?

Again: thank you for the help.

Edited by Guilherme Amorim

Share this post


Link to post
Share on other sites
Yea. Note that if you get the raw pixel data from the decoded bitmap, you can use it with any rendering API, not just D2D :)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!