Using Image as a Resource

Started by
9 comments, last by yewbie 12 years, 9 months ago
Hi..I wanted to store some images as a resource. I read somewhere that by storing images as a resource u can compile it in the exe and hence avoid it being tampered with..

Can somebody tell me how to do it ?
Can we also store a .dds file as a resource and then use D3DXCreateTextureFromtResourceEx() to create a texture from it..??
Advertisement
To load an image from a resource file, use LoadImage(). To load a DDS surface from a resource, follow the directions in answer to this post.





EDIT: FYI, package an image in a resource dll will not prevent access to it, using various tools the image can still be accessed and to a lesser degree, modified.


It may be to your advantage to package all your resources into a single file, XML probably makes as much sense as anything. Loading all of your files from a single file is generally the better option performance wise, and if you wish, you could encrypt your data files, then decrypt them on load.Even if you don't want to use XML, writing a tool that smushes a number of files together and prepends a primitive index of file contents would be a trivial exercise.
Sorry..let me reframe my question..I want to know how to store an image as a resource or how to place an image file in my resource file(if there is any such resource file)..
and I didn't understand where to use RT_RCDATA or RT_BITMAP type in my code.
Also the second parameter to D3DXCreateTextureFromResourceEx() I could not understand(http://msdn.microsoft.com/en-us/library/bb172805%28VS.85%29.aspx)..what is the module.

I want to do this so that I can practice using the function D3DXCreateTextureFromResourceEx().

Please explain..
Thank you guys..
Thanks Serapth for your reply..

It may be to your advantage to package all your resources into a single file, XML probably makes as much sense as anything[/quote] .

Can u tell me how to use xml for storing resources or can u guide me somewhere(online tutorial,code,article,link,book) that can tell me how to do it..and then how to use that resource eg: an image stored in xml file in my DirectX code..

Thanks again..
How you add a resource to an application depends on your exact compiler and toolchain. Resources can be attached to both executables and DLLs. The HMODULE parameter tells the function which executable or DLL to load the resource from. For a DLL you generally use the result of LoadLibrary() or LoadLibraryEx() as the HMODULE argument.

Thanks Serapth for your reply..

It may be to your advantage to package all your resources into a single file, XML probably makes as much sense as anything
.

Can u tell me how to use xml for storing resources or can u guide me somewhere(online tutorial,code,article,link,book) that can tell me how to do it..and then how to use that resource eg: an image stored in xml file in my DirectX code..

Thanks again..
[/quote]


Well, like I said, you can roll your own resource manager. There is an example on this very site of how to do it in C++. I am by no means endorsing ( nor condeming ) this code, it simply turned up in a quick search, but it covers the gist of what I meant earlier about smushing all your content together with a table of contents prepended. SFML have a similar article posted about how to organize resources in a single file.


When I suggested XML earlier, I did so mostly from the perspective of being a non-C++ developer. In C# for example, serializing and deserializing an object to and from XML is trivially easy. That said, in C++ it was a much trickier task. Frankly I simply don't work much with C++ these days, so I do not know if a better XML library has come along in recent years. If you want to go the XML route, I would ask someone else for clarification on the best way to do it. The last XML library I used ( for mobile development in this case ) in C++ was libxml2 but I imagine there are much better options these days.

If you wish, you could encrypt your data files, then decrypt them on load.


This is fairly pointless as as soon as you display the image, tools exist to get hold of it in plain form.

It is pretty much impossible to protect resources with technology. If there is a real need (and there probably isn't), only legal protection is plausible and that tends to cost money.

If you are merely trying to stop casual users from double-clicking a file to open it in Paint, you may as well just change the file extension. That will deter a casual user and anyone bright enough to change the extension back will be bright enough to press the Print Screen button or use something like Fraps to take a screenshot while the program is running anyway.

Main purpose of packing resources into a single file is to reduce file count and ease compression, not for security.
Thanks guys for your replies..
Heh, it makes me think that some day Microsoft will add a game/program IP protection service that prevents screenshotting copyrighted materials.

I can see it now, the little paper clip guy comes up and says, "I noticed you pressed Print Screen, you currently are running (Insert application name here). I went ahead and blacked out that portion of the screen shot for you, click here to learn about IP laws."

Dark times =p

Heh, it makes me think that some day Microsoft will add a game/program IP protection service that prevents screenshotting copyrighted materials.

I can see it now, the little paper clip guy comes up and says, "I noticed you pressed Print Screen, you currently are running (Insert application name here). I went ahead and blacked out that portion of the screen shot for you, click here to learn about IP laws."

Dark times =p



Actually, it exists to a certain degree. This is the core of HDCP which was forced down our throat with HDMI. If a company really cared enough, they could restrict their game to HDCP compatible devices only and send all visual information encrypted.



In this case though, Blame Intel, not Microsoft. Actually, MS has always actually been pretty pro-consumer in their approach to IP protection. They do what they have to in order to support their OEM customers, but for the most part, keep away from truly draconian measures. Well, except Palladium, but hey... it died thankfully.

This topic is closed to new replies.

Advertisement