LEADTOOLS GDI/GDI+(Leadtools.Drawingアセンブリ)

フレームを表示

ConvertToRegionHandleメソッド






ソースLEADTOOLSリージョン。このパラメーターは、null(Visual BasicではNothing)であるはずがありません。
表示座標と画像座標の間で変換するために使用するLeadtools.RasterRegionXFormオブジェクト。
LEADTOOLS Leadtools.RasterRegionをGDI HRGNオブジェクトに変換します。
構文
public static IntPtr ConvertToRegionHandle( 
   RasterRegion region,
   RasterRegionXForm xform
)
'Declaration
 
Public Shared Function ConvertToRegionHandle( _
   ByVal region As RasterRegion, _
   ByVal xform As RasterRegionXForm _
) As IntPtr
'Usage
 
Dim region As RasterRegion
Dim xform As RasterRegionXForm
Dim value As IntPtr
 
value = RasterRegionConverter.ConvertToRegionHandle(region, xform)
public:
static IntPtr ConvertToRegionHandle( 
   RasterRegion^ region,
   RasterRegionXForm^ xform
) 

パラメーター

リージョン
ソースLEADTOOLSリージョン。このパラメーターは、null(Visual BasicではNothing)であるはずがありません。
xform
表示座標と画像座標の間で変換するために使用するLeadtools.RasterRegionXFormオブジェクト。

戻り値

このメソッドが作成するGDI HRGNオブジェクト。Windows DeleteObject APIを用いてそれを使った後に、このオブジェクトを削除しなければなりません。
解説

LEADTOOLS Leadtools.RasterRegionクラスは、GDI、GDI+、WPFとSilverlightなどのLEADTOOLSによってサポートされる任意のプラットホームで使われることができるLeadtools.RasterImageで、関心領域のプラットホームから独立した表現を提供します。LEADTOOLS Leadtools.RasterRegionオブジェクトとGDI HRGNとSystem.Drawing(GDI+)System.Drawing.Regionオブジェクトの間で変換するには、このクラスを使用します。

詳細については、「RasterImageとGDI/GDI+」を参照してください。

サンプル
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.ImageProcessing
Imports 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 IntPtr
End Function
<DllImport("Gdi32")> _
Private Shared Function DeleteObject(ByVal hObject As IntPtr) As Integer
End Function
<DllImport("Gdi32")> _
Private Shared Function OffsetRgn(ByVal hrgn As IntPtr, ByVal nXOffset As Integer, ByVal nYOffset As Integer) As Integer
End Function
<TestMethod()> _
Public Sub RasterRegionHandleExample()
   ' Load an image 
   Dim 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 region
   Dim gdiRegion As IntPtr = CreateEllipticRgn(100, 200, 100 + 400, 200 + 300)

   ' Create a RasterRegion from this region
   Using region As RasterRegion = RasterRegionConverter.ConvertFromRegionHandle(gdiRegion)
      ' Add this region to the image
      image.SetRegion(Nothing, region, RasterRegionCombineMode.Set)
   End Using

   DeleteObject(gdiRegion)

   ' Fill the image with a color
   Dim cmd As New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Red))
   cmd.Run(image)

   ' Save it
   codecs.Save(image, dstFileName1, RasterImageFormat.Jpeg, 24)

   ' Now get the GDI+ region from the image
   Using 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 bottom
   OffsetRgn(gdiRegion, 100, 100)

   ' Re-set it into the image, fill again and save
   ' Create a RasterRegion from this region
   Using region As RasterRegion = RasterRegionConverter.ConvertFromRegionHandle(gdiRegion)
      ' Add this region to the image
      image.SetRegion(Nothing, region, RasterRegionCombineMode.Set)
   End Using

   DeleteObject(gdiRegion)

   ' Fill the image with a color
   cmd = New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow))
   cmd.Run(image)

   ' Save it
   codecs.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);
[TestMethod]
public void RasterRegionHandleExample()
{
   // Load an image 
   string 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 region
   IntPtr gdiRegion = CreateEllipticRgn(100, 200, 100 + 400, 200 + 300);

   // Create a RasterRegion from this region
   using(RasterRegion region = RasterRegionConverter.ConvertFromRegionHandle(gdiRegion))
   {
      // Add this region to the image
      image.SetRegion(null, region, RasterRegionCombineMode.Set);
   }

   DeleteObject(gdiRegion);

   // Fill the image with a color
   FillCommand cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Red));
   cmd.Run(image);

   // Save it
   codecs.Save(image, dstFileName1, RasterImageFormat.Jpeg, 24);

   // Now get the GDI+ region from the image
   using(RasterRegion region = image.GetRegion(null))
   {
      // Convert it to GDI+
      gdiRegion = RasterRegionConverter.ConvertToRegionHandle(region, null);
   }

   // Move the region 100 pixels to the right and bottom
   OffsetRgn(gdiRegion, 100, 100);

   // Re-set it into the image, fill again and save
   // Create a RasterRegion from this region
   using(RasterRegion region = RasterRegionConverter.ConvertFromRegionHandle(gdiRegion))
   {
      // Add this region to the image
      image.SetRegion(null, region, RasterRegionCombineMode.Set);
   }

   DeleteObject(gdiRegion);

   // Fill the image with a color
   cmd = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Yellow));
   cmd.Run(image);

   // Save it
   codecs.Save(image, dstFileName2, RasterImageFormat.Jpeg, 24);

   image.Dispose();

   codecs.Dispose();
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
必要条件

ターゲットプラットホーム

参照

参照

RasterRegionConverterクラス
RasterRegionConverterメンバ