4

I'm trying to create a card game in C# and for this I have alot of images that I need to load. They're all jpg images and there are about 7000 of them.

I would like to make sure that if you download the game, the images will not be easily accessible, meaning that they should not just be JPG images in a sub folder of the application. So I thought about imbedding them in a DLL file.

But how do I do this? And how do I handle this efficiently? Is there a tecnique to this sort of thing, or is another method preferable?

Daniel Olsen
  • 1,020
  • 2
  • 15
  • 27

3 Answers3

3

I would like to make sure that [...] the images will not be easily accessible

First, you should ask yourself why you want to forbid this. If you just want to avoid that someone else manipulates the pictures, you can leave them in a bunch of subfolders as JPGs, just generate checksums for each file and check them at the time the program loads the pictures.

If you want to avoid reuse of the pictures, you can leave them in a bunch of subfolders, but not as JPGs. Encode them with for example with the standard AES algorithm. But beware, that won't prevent anyone else of making screenshots while you application is running, so you should consider if that's really worth the effort.

EDIT: if you want to embed the images because installation gets easier when you have just one big file to deploy instead of 7000 single files, then you may write a helper program for creating resource files programmatically. See this page from Microsoft, especially the part about .resource files, to learn how to utilize the ResourceWriter class for that purpose.

Doc Brown
  • 19,739
  • 7
  • 52
  • 88
1

If you have 7000 image, you need a database. Microsoft SQL Server Compact 4.0 is an option. It's small and easy to use.

Vano Maisuradze
  • 5,829
  • 6
  • 45
  • 73
  • A database can be helpful or overkill, that depends on a lot of things not mentioned in the original question. – Doc Brown Jul 31 '12 at 06:48
1

I'm assuming that this is a windows application

In order to Embed a Image to the assembly

1. Right click the Image file and Select properties
2. In the Properties Pane Set the BuildAction as Embeded resource

So this Image becomes a embeded resource when the application is compiled

Then you can access the Image from the assembly like:

global::[[MyNameSpace]].Properties.Resources.[[ImageName]]

for eg:this.pictureBox1.Image = global::[[MyNameSpace]].Properties.Resources.[[ImageName]]

shajivk
  • 570
  • 1
  • 6
  • 13
  • ... and now repeat this 7000 times and you are ready? The question was how to achieve this programmatically, not manually, which is trivial. – Doc Brown Jul 31 '12 at 16:40
  • 1
    programatically embed resources in assembly : http://stackoverflow.com/questions/1107912/programmically-embed-resources-in-a-net-assembly – shajivk Jul 31 '12 at 17:48