ChangeToImage Method
Syntax
Parameters
options
The conversion options.
Return Value
The GDI+ image that this method creates.
Example
This example changes between a Leadtools.RasterImage and a GDI+ image.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
public void ChangeToImageExample()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "GdiPlusImage1.bmp");
// Load the image
using (RasterImage srcImage = codecs.Load(srcFileName))
{
// Convert to GDI+ image
ImageIncompatibleReason reason = RasterImageConverter.TestCompatible(srcImage, true);
PixelFormat pf = RasterImageConverter.GetNearestPixelFormat(srcImage);
Console.WriteLine("TestCompatible: {0}", reason);
Console.WriteLine("GetNearestPixelFormat:{0}", pf);
if (reason != ImageIncompatibleReason.Compatible)
{
RasterImageConverter.MakeCompatible(srcImage, pf, true);
}
using (Image destImage = RasterImageConverter.ChangeToImage(srcImage, ChangeToImageOptions.ForceChange))
{
// Save this image to disk
destImage.Save(destFileName, ImageFormat.Bmp);
}
}
// Clean up
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color
Public Sub ChangeToImageExample()
Dim codecs As New RasterCodecs()
Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "GdiPlusImage1.bmp")
' Load the image
Using srcImage As RasterImage = codecs.Load(srcFileName)
' Convert to GDI+ image
Dim reason As ImageIncompatibleReason = RasterImageConverter.TestCompatible(srcImage, True)
Dim pf As PixelFormat = RasterImageConverter.GetNearestPixelFormat(srcImage)
Console.WriteLine("TestCompatible: {0}", reason)
Console.WriteLine("GetNearestPixelFormat:{0}", pf)
If reason <> ImageIncompatibleReason.Compatible Then
RasterImageConverter.MakeCompatible(srcImage, pf, True)
End If
Using destImage As Image = RasterImageConverter.ChangeToImage(srcImage, ChangeToImageOptions.ForceChange)
' Save this image to disk
destImage.Save(destFileName, ImageFormat.Bmp)
End Using
End Using
' Clean up
codecs.Dispose()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images"
End Class