Converts a LEADTOOLS Leadtools.RasterRegion to a GDI HRGN object.
public static IntPtr ConvertToRegionHandle(Leadtools.RasterRegion region,Leadtools.RasterRegionXForm xform)
Public Shared Function ConvertToRegionHandle( _ByVal region As Leadtools.RasterRegion, _ByVal xform As Leadtools.RasterRegionXForm _) As IntPtr
public:static IntPtr ConvertToRegionHandle(Leadtools.RasterRegion^ region,Leadtools.RasterRegionXForm^ xform)
region
The source LEADTOOLS region. This parameter cannot be null (Nothing in VB).
xform
Leadtools.RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates.
The GDI HRGN object this method creates. You must delete this object after using it using the Windows DeleteObject API.
The LEADTOOLS Leadtools.RasterRegion class provides a platform independent representation of an area of interest in a Leadtools.RasterImage that can be used in any platform supported by LEADTOOLS such as GDI, GDI+, WPF and Silverlight. Use this class To convert a LEADTOOLS Leadtools.RasterRegion object to/from a GDI HRGN and System.Drawing (GDI+) System.Drawing.Region object.
For more information refer to RasterImage and GDI/GDI+.
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.DrawingImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.Color' Windows API to use in this example<DllImport("Gdi32")> _Private Shared Function CreateEllipticRgn(ByVal nLeftRect As Integer, ByVal nTopRect As Integer, ByVal nRightRect As Integer, ByVal nBottomRect As Integer) As IntPtrEnd Function<DllImport("Gdi32")> _Private Shared Function DeleteObject(ByVal hObject As IntPtr) As IntegerEnd Function<DllImport("Gdi32")> _Private Shared Function OffsetRgn(ByVal hrgn As IntPtr, ByVal nXOffset As Integer, ByVal nYOffset As Integer) As IntegerEnd Function<TestMethod()> _Public Sub RasterRegionHandleExample()' Load an imageDim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"Dim dstFileName1 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_Ellipse.jpg"Dim dstFileName2 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_EllipseTranslated.jpg"Dim codecs As New RasterCodecs()Dim image As RasterImage = codecs.Load(srcFileName)' We will add an ellipse region to the image' Using GDI, create an elliptical regionDim gdiRegion As IntPtr = CreateEllipticRgn(100, 200, 100 + 400, 200 + 300)' Create a RasterRegion from this regionUsing region As RasterRegion = RasterRegionConverter.ConvertFromRegionHandle(gdiRegion)' Add this region to the imageimage.SetRegion(Nothing, region, RasterRegionCombineMode.Set)End UsingDeleteObject(gdiRegion)' Fill the image with a colorDim cmd As New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Red))cmd.Run(image)' Save itcodecs.Save(image, dstFileName1, RasterImageFormat.Jpeg, 24)' Now get the GDI+ region from the imageUsing region As RasterRegion = image.GetRegion(Nothing)' Convert it to GDI+gdiRegion = RasterRegionConverter.ConvertToRegionHandle(region, Nothing)End Using' Move the region 100 pixels to the right and bottomOffsetRgn(gdiRegion, 100, 100)' Re-set it into the image, fill again and save' Create a RasterRegion from this regionUsing region As RasterRegion = RasterRegionConverter.ConvertFromRegionHandle(gdiRegion)' Add this region to the imageimage.SetRegion(Nothing, region, RasterRegionCombineMode.Set)End UsingDeleteObject(gdiRegion)' Fill the image with a colorcmd = New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow))cmd.Run(image)' Save itcodecs.Save(image, dstFileName2, RasterImageFormat.Jpeg, 24)image.Dispose()codecs.Dispose()End Sub
using Leadtools;using Leadtools.Codecs;using Leadtools.Drawing;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;// Windows API to use in this example[DllImport("Gdi32")]private static extern IntPtr CreateEllipticRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);[DllImport("Gdi32")]private static extern int DeleteObject(IntPtr hObject);[DllImport("Gdi32")]private static extern int OffsetRgn(IntPtr hrgn, int nXOffset, int nYOffset);public void RasterRegionHandleExample(){// Load an imagestring srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");string dstFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_Ellipse.jpg");string dstFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_EllipseTranslated.jpg");RasterCodecs codecs = new RasterCodecs();RasterImage image = codecs.Load(srcFileName);// We will add an ellipse region to the image// Using GDI, create an elliptical regionIntPtr gdiRegion = CreateEllipticRgn(100, 200, 100 + 400, 200 + 300);// Create a RasterRegion from this regionusing(RasterRegion region = RasterRegionConverter.ConvertFromRegionHandle(gdiRegion)){// Add this region to the imageimage.SetRegion(null, region, RasterRegionCombineMode.Set);}DeleteObject(gdiRegion);// Fill the image with a colorFillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Red));cmd.Run(image);// Save itcodecs.Save(image, dstFileName1, RasterImageFormat.Jpeg, 24);// Now get the GDI+ region from the imageusing(RasterRegion region = image.GetRegion(null)){// Convert it to GDI+gdiRegion = RasterRegionConverter.ConvertToRegionHandle(region, null);}// Move the region 100 pixels to the right and bottomOffsetRgn(gdiRegion, 100, 100);// Re-set it into the image, fill again and save// Create a RasterRegion from this regionusing(RasterRegion region = RasterRegionConverter.ConvertFromRegionHandle(gdiRegion)){// Add this region to the imageimage.SetRegion(null, region, RasterRegionCombineMode.Set);}DeleteObject(gdiRegion);// Fill the image with a colorcmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow));cmd.Run(image);// Save itcodecs.Save(image, dstFileName2, RasterImageFormat.Jpeg, 24);image.Dispose();codecs.Dispose();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
|
Products |
Support |
Feedback: ConvertToRegionHandle Method - Leadtools.Drawing |
Introduction |
Help Version 19.0.2017.3.21
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.