LEADTOOLS GDI/GDI+ (Leadtools.Drawing assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
AddRegionToRegion(RasterImage,RasterRegionXForm,Region,RasterRegionCombineMode) Method
See Also 



image
The source image.
xform
Leadtools.RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates. If you specify null (Nothing in Visual Basic) in this parameter, the scalar fields default to 1, the offsets default to 0, and the view perspective defaults to the image view perspective.
region
The GDI+ region to add.
combineMode
The action to take regarding the existing image region, if one is defined.
image
The source image.
xform
Leadtools.RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates. If you specify null (Nothing in Visual Basic) in this parameter, the scalar fields default to 1, the offsets default to 0, and the view perspective defaults to the image view perspective.
region
The GDI+ region to add.
combineMode
The action to take regarding the existing image region, if one is defined.
Creates or updates a LEADTOOLS image region by adding the specified GDI+ region.

Syntax

Visual Basic (Declaration) 
Overloads Public Shared Sub AddRegionToRegion( _
   ByVal image As RasterImage, _
   ByVal xform As RasterRegionXForm, _
   ByVal region As Region, _
   ByVal combineMode As RasterRegionCombineMode _
) 
Visual Basic (Usage)Copy Code
Dim image As RasterImage
Dim xform As RasterRegionXForm
Dim region As Region
Dim combineMode As RasterRegionCombineMode
 
RasterRegionConverter.AddRegionToRegion(image, xform, region, combineMode)
C# 
public static void AddRegionToRegion( 
   RasterImage image,
   RasterRegionXForm xform,
   Region region,
   RasterRegionCombineMode combineMode
)
C++/CLI 
public:
static void AddRegionToRegion( 
   RasterImage^ image,
   RasterRegionXForm^ xform,
   Region^ region,
   RasterRegionCombineMode combineMode
) 

Parameters

image
The source image.
xform
Leadtools.RasterRegionXForm object that LEADTOOLS uses to translate between display coordinates and image coordinates. If you specify null (Nothing in Visual Basic) in this parameter, the scalar fields default to 1, the offsets default to 0, and the view perspective defaults to the image view perspective.
region
The GDI+ region to add.
combineMode
The action to take regarding the existing image region, if one is defined.

Example

Visual BasicCopy Code
Public Sub AddRegionToRegionGdip_Example()
   Dim codecs As New RasterCodecs()

   Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
   Dim destFileName1 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_ConvertToRegion.bmp"
   Dim destFileName2 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_AddRegionToRegion.bmp"

   ' Load the image
   Dim image As RasterImage = codecs.Load(srcFileName)

   ' Add an ellipse inside a rectangle region to the image

   Dim rc As New LeadRect(image.Width \ 3, image.Height \ 3, image.Width \ 3, image.Height \ 3)
   image.AddEllipseToRegion(Nothing, rc, RasterRegionCombineMode.Set)

   ' Create a GDI+ image from this raster image, then obtain a Graphics
   ' object to the GDI+ image, apply the region to it then fill it with red color
   Dim region As Region

   Using gdiPlusImage As Image = RasterImageConverter.ConvertToImage(image, ConvertToImageOptions.None)
      Using graphics As Graphics = graphics.FromImage(gdiPlusImage)
         Using rasterRegion As RasterRegion = image.GetRegion(Nothing)
            region = RasterRegionConverter.ConvertToRegion(rasterRegion, Nothing)
            graphics.Clip = region

            ' This call should only fill the ellipse
            graphics.FillRectangle(Brushes.Red, 0, 0, image.Width, image.Height)
         End Using
      End Using

      gdiPlusImage.Save(destFileName1, ImageFormat.Bmp)
   End Using

   ' Empty the region in the raster image and re-add it through the
   ' region object we got with AddRegionToRegion
   image.MakeRegionEmpty()

   RasterRegionConverter.AddRegionToRegion(image, Nothing, region, RasterRegionCombineMode.Set)
   Dim command As New FillCommand()
   command.Color = RasterColor.FromKnownColor(RasterKnownColor.Red)
   command.Run(image)
   codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 24)

   region.Dispose()
   image.Dispose()
   codecs.Dispose()
End Sub
C#Copy Code
public void AddRegionToRegionGdip_Example()
   {
      RasterCodecs codecs = new RasterCodecs();

      string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
      string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_ConvertToRegion.bmp");
      string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_AddRegionToRegion.bmp");

      // Load the image
      RasterImage image = codecs.Load(srcFileName);

      // Add an ellipse inside a rectangle region to the image

      LeadRect rc = new LeadRect(image.Width / 3, image.Height / 3, image.Width / 3, image.Height / 3);
      image.AddEllipseToRegion(null, rc, RasterRegionCombineMode.Set);

      // Create a GDI+ image from this raster image, then obtain a Graphics
      // object to the GDI+ image, apply the region to it then fill it with red color
      Region region;

      using(Image gdiPlusImage = RasterImageConverter.ConvertToImage(image, ConvertToImageOptions.None))
      {
         using(Graphics graphics = Graphics.FromImage(gdiPlusImage))
         {
            using(RasterRegion rasterRegion = image.GetRegion(null))
            {
               region = RasterRegionConverter.ConvertToRegion(rasterRegion, null);
               graphics.Clip = region;

               // This call should only fill the ellipse
               graphics.FillRectangle(Brushes.Red, 0, 0, image.Width, image.Height);
            }
         }

         gdiPlusImage.Save(destFileName1, ImageFormat.Bmp);
      }

      // Empty the region in the raster image and re-add it through the
      // region object we got with AddRegionToRegion
      image.MakeRegionEmpty();

      RasterRegionConverter.AddRegionToRegion(image, null, region, RasterRegionCombineMode.Set);
      FillCommand command = new FillCommand();
      command.Color = RasterColor.FromKnownColor(RasterKnownColor.Red);
      command.Run(image);
      codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 24);

      region.Dispose();
      image.Dispose();
      codecs.Dispose();
   }

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

Remarks

To update an existing region, you specify how the new region is to be combined with the existing one using the combineMode parameter. For more information, refer to Leadtools.RasterRegionCombineMode.

For more information, refer to Creating a Region.

For more information, refer to Saving A Region.

For more information, refer to Working with the Existing Region.

For more information, refer to The RasterPaintEngine Property and 16bpp Grayscale Images.

For more information refer to RasterImage and GDI/GDI+.

Requirements

Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also