Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# ImageFormat to string

Tags:

c#

image

How can I obtain human readable string(i.e. image format itself) from System.Drawing.ImageFormat object?

I mean if I have ImageFormat.Png is that possible to convert it to "png" string?

EDIT: I see some misunderstanding here. Here is mine code:

Image objImage = Image.FromStream(file);

ImageFormat imFormat = objImage.RawFormat;

imFormat.ToString(); 

It returns "[ImageFormat: b96b3caf-0728-11d3-9d7b-0000f81ef32e]" but I want "Png"!

like image 400
Michael Z Avatar asked Dec 13 '11 13:12

Michael Z


1 Answers

Use the ImageFormatConverter class from the System.Drawing namespace:

this.imageInfoLabel.Text = 
    new ImageFormatConverter().ConvertToString(this.Image.RawFormat);

For a PNG image it returns Png, and so on.

like image 60
Alex Vang Avatar answered Sep 28 '22 11:09

Alex Vang