ward87
ward87

Reputation: 3026

Binary Image Extension?

When we convert an image to binary data, (let's say a .png image) is there a way to get the extension back while converting the binary to image again in .net?

Upvotes: 1

Views: 1781

Answers (1)

Jodrell
Jodrell

Reputation: 35716

Short answer, no. You can't get the name either. The file name is not generally stored in image data.

If you know what the image format is you can use either a sensible, generally recognised extension or a file extension registered to that file type on your system. Hopefully, these will not differ.

If you don't know the format perhaps you could read it before serialising to binary and prefix it to the representation.

For a less general answer please expand your question.

EDIT

I guess you could attempt to display the image using a set of potential formats, then visually assess all succesful decodes to choose the correct format. Somehow, it seems easier to just include the original extension in the binary serialization.

Upvotes: 1

Related Questions