Mediator
Mediator

Reputation: 15378

How to store images do not use the resources

I have a C # application and I need to keep in her pictures, but I can not use resources (resx). Is there then an alternative method?

update: ANSWER: My images is static, for this I will use Embedded Resource

How create embedded resource

Upvotes: 0

Views: 305

Answers (6)

Tigran
Tigran

Reputation: 62266

I would go on my line: you can save on disk by using any Mono ZIP library that provides secure encryption.

Zip: cause you potentially will save a space

Encryption: if you need save some private data (family images, documents...)

Can group them based on your own app logic, or save them individually, with also some metafile attached, if you need also provide some information on image.

Microsoft uses this kind of "technology" for example for DOCX files. Try to change an extension of DOCX file to ZIP and unzip it into the folder. You will see the content.

Regards.

Upvotes: 0

Icemanind
Icemanind

Reputation: 48696

Given the options you gave us, that doesn't leave us with much to work with. Depending on the image size, you can use this website to encoding your images to Base64 and then store them in a string. Then you can use System.Convert.FromBase64String to convert them from base64 back to a byte array.

Another option would be to store your images on a web server and create a webservice on the server that you can consume to retreive the images.

These are not good methods though. The first idea is consuming a lot more memory then it would need to and the second method is just kind of ridiculous if you think about it. It is much much much better to use a database. You can use a database such as MySQL that will work with both Windows and Mono. You can also use SQLite database so that the database is portable. There really isn't a good reason to store this in a database.

Upvotes: 0

viggity
viggity

Reputation: 15237

As mentioned above, it really depends on whether or not they are static or dynamic. If static, you could use an Embedded Resource (instead of encoding them as constant byte arrays, as others have mentioned). If dynamic, you could store them in isolated storage.

Upvotes: 2

George Mamaladze
George Mamaladze

Reputation: 7931

If images are not too large you can encode them into huge constant arrays in code. This is not very elegant solution but what else if no file, no resource, no database?

Upvotes: 0

svick
svick

Reputation: 244868

One idea comes to mind, but I probably wouldn't use it if at all possible: put the images into your code as arrays of bytes.

You could create byte[] fields for the images and initialize them in code. You could dynamically generate the code using either CodeDOM or Reflection.Emit.

Upvotes: 0

Gregory A Beamer
Gregory A Beamer

Reputation: 17010

Is this a dynamic set of pictures or static? If static, you can compile the resource file as a separate assembly and then consume it. If dynamic, you need some type of data store to store the files. If file system does not work, a database is an option.

Upvotes: 1

Related Questions