Jump to content
  • Advertisement
Sign in to follow this  
Thevenin

Embedding resources into a C# application.

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

I don't know why I'm having soo much difficulty with this, but here is what I'm trying to do. I want to hide the PNG resources of my game from the players. The easiest way to do this, I'd imagine, is to embed them as a resource into the .EXE. However, when I do this, I only seem to be able to get a .NET Bitmap object when I try to access the files. Can I get a stream? Or better yet, access it like a file? The reason being that DirectX's Textureloader wants a Stream or a File, I can't work with a Bitmap. Least, I don't think I can work with a bitmap. Using 'new Texture(TheBitmap)' is programmed into MDirectX but I don't know how to work it, cause every time I try to use it, the application freezes up. =/ Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You can read the resource like My.Resources.Resource.(resource name). But in your case you want to read it as a byte[] as you stream it in. You can use a memory stream class to read the object if you want. But the image object can do a lot of things to like converting formats, and reading them, so you may think twice about reading it as a byte array, because then you'll have to convert it back to png again if your using it in your exe.

Share this post


Link to post
Share on other sites
This is how I get embedded resource streams out of the assembly:

Stream tempStream = Assembly.GetEntryAssembly().GetManifestResourceStream("WhateverDefaultNameSpace.FILENAME.EXT");
this.Icon = new System.Drawing.Icon(tempStream);

The "WhateverDeafultNameSpace" is whatever you have it set to in the assembly's project properties. The FiLENAME.EXT is pretty straight forward.

HTH

Share this post


Link to post
Share on other sites
Quote:
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MClient")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("N/A")]
[assembly: AssemblyProduct("MClient")]
[assembly: AssemblyCopyright("Copyright © N/A 2005")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]


Which one of these, cause none appear to work. [depressed]

Share this post


Link to post
Share on other sites
Oops, oh wait, nm. It works, I just forgot to set the resource to be an "Embedded Resource".

Thanks. =)

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!