Click or drag to resize

BitmapExtensionsConvertTo(Image, ImageFormat) Method

Converts a Bitmap image to the specified ImageFormat.

Namespace: GSF.Drawing
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax
public static Bitmap ConvertTo(
	this Image originalImage,
	ImageFormat newFormat
)
View Source

Parameters

originalImage  Image
The Bitmap image to be converted.
newFormat  ImageFormat
The new ImageFormat of the image.

Return Value

Bitmap
A Bitmap instance.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Image. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Example
This example shows how to convert the format of an image:
C#
using System;
using System.Drawing;
using System.Drawing.Imaging;
using GSF.Drawing;

class Program
{
    static void Main(string[] args)
    {
        // Load the original image.
        Bitmap original = (Bitmap)Bitmap.FromFile("Original.jpg");
        // Convert the original image.
        Bitmap originalGif = original.ConvertTo(ImageFormat.Gif);
        // Save the converted image to file.
        originalGif.Save("OriginalGif.gif");

        // Clean-up.
        original.Dispose();
        originalGif.Dispose();

        Console.ReadLine();
    }
}
See Also