Click or drag to resize

BitmapExtensionsConvertTo(Image, ImageFormat, Boolean) 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,
	bool disposeOriginal
)
View Source

Parameters

originalImage  Image
The Bitmap image to be converted.
newFormat  ImageFormat
The new ImageFormat of the image.
disposeOriginal  Boolean
true if the original image is to be disposed after converting it; otherwise false.

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 and dispose the original image that was converted:
C#
using System;
using System.Drawing;
using System.Drawing.Imaging;
using GSF.Drawing;

class Program
{
    static void Main(string[] args)
    {
        // Load original, convert it, and dispose original.
        using (Bitmap converted = ((Bitmap)Bitmap.FromFile("Original.jpg")).ConvertTo(ImageFormat.Gif))
        {
            // Save the converted image to file.
            converted.Save("OriginalGif.gif");
        }

        Console.ReadLine();
    }
}
See Also