Software & Finance

C# - Displaying Images and Convering Type between jpeg, tiff, png, bmp, etc

C# provides an easy to way to load and display images on the screen very easily. You need to write only couple of lines of code to implement this. Besides changing the image type (like convert bmp to jpeg or tiff or png) is also very easy to implement.

System.Drawing.Image is the class you can use to load images and save it as another type.

To know the list of image files supported, loot at System.Drawing.Imaging.ImageFormat


Source Code

void LoadImage(Graphics g, string filename)


        Image MyImg = Image.FromFile(filename);


              new RectangleF(



                  MyImg.Width / 2,

                  MyImg.Height / 2)



MyImg.Save("c:\\r.gif", System.Drawing.Imaging.ImageFormat.Gif);

MyImg.Save("c:\\r.png", System.Drawing.Imaging.ImageFormat.Png);

MyImg.Save("c:\\r.tiff", System.Drawing.Imaging.ImageFormat.Tiff); 





Displays the loaded image