Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, March 8, 2017 2:55:24 PM(UTC)

Hadi  
Hadi

Groups: Manager, Tech Support, Administrators
Posts: 218

Was thanked: 12 time(s) in 12 post(s)

The LEADTOOLS Imaging SDK has a RasterImageConverter Class in the Leadtools.Drawing.dll that will help convert to and from a GDI and GDI+ Image object into a LEADTOOLS RasterImage object.
https://www.leadtools.com/help/sdk/dh/ld/rasterimageconverter.html

The 2 methods that do the converting are the ConvertoToImage and ConvertFromImage methods:

ConvertToImage Method
https://www.leadtools.com/help/sdk/dh/ld/rasterimageconverter-converttoimage.html

ConvertFromImage Method
https://www.leadtools.com/help/sdk/dh/ld/rasterimageconverter-convertfromimage.html

Here is an example of how to Convert from a RasterImage to a GDI+ Image and then back:

C#
Code:
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 destImage1 = RasterImageConverter.ConvertToImage(srcImage, ConvertToImageOptions.None))
    {
        // Save this image to disk
        destImage1.Save(destFileName1, ImageFormat.Bmp);

        // Convert the GDI+ image back to a RasterImage
        using(RasterImage destImage2 = RasterImageConverter.ConvertFromImage(destImage1, ConvertFromImageOptions.None))
        {
            // Save it to disk
            codecs.Save(destImage2, destFileName2, RasterImageFormat.Bmp, 24);
        }
    }
}


VB
Code:
' 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 destImage1 As Image = RasterImageConverter.ConvertToImage(srcImage, ConvertToImageOptions.None)
        ' Save this image to disk
        destImage1.Save(destFileName1, ImageFormat.Bmp)

        ' Convert the GDI+ image back to a RasterImage
        Using destImage2 As RasterImage = RasterImageConverter.ConvertFromImage(destImage1, ConvertFromImageOptions.None)
            ' Save it to disk
            codecs.Save(destImage2, destFileName2, RasterImageFormat.Bmp, 24)
        End Using
    End Using
End Using

Edited by moderator Wednesday, December 27, 2023 2:25:45 PM(UTC)  | Reason: Updated links

Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.

LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.037 seconds.