In This Topic
Programming / Document Viewing / Drawing highlighted regions within the GdViewer using the mouse

Drawing highlighted regions within the GdViewer using the mouse

In This Topic

Highlighted regions are one of the special features of GdPicture. They are modifiable by mouse, they can be easily used to specify areas and highlight them and they are especially useful in Anchor and OMR applications. Here we will learn how to add them on the top of a document displayed within the GdViewer object.

Copy Code
'We assume that GdPicture has been correctly installed and unlocked.
'We assume the GdViewer object called GdViewer1 has been created and painted on the form.
Dim oGdPictureImaging As New GdPictureImaging
'Loading the image from a file.
Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("C:\\Image.tif")
'Checking if the image resource has been loaded correctly.
If oGdPictureImaging.GetStat() <> GdPictureStatus.OK
   MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Drawing regions Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
   'Displaying the image in the GdViewer.
   GdViewer1.DisplayFromGdPictureImage(imageId)
End If
oGdPictureImaging.Dispose()

'On the Mouse UP event on the GdViewer, create a highlighted region based on the rectangle of selection of the GdViewer.
'If no rectangle of selection is painted on the GdViewer, this event will do nothing.
Public Sub Draw_Region(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles GdViewer1.MouseUp
   'Initializing variables to hold the position of the rectangle of selection on the document.
   Dim leftArea As Integer, topArea As Integer, widthArea As Integer, heightArea As Integer
   'Checking if a rectangle of selection has been painted on the GdViewer.
   If GdViewer1.IsRect() Then
      'Getting the location of the selection on the document.
      GdViewer1.GetRectCoordinatesOnDocument(leftArea, topArea, widthArea, heightArea)
      'Setting the ROI on the document:
      'Adding a region in place of the rectangle of selection.
      Dim regionId As Integer = GdViewer1.AddRegion("Region", leftArea, topArea, widthArea, heightArea, GdPicture14.ForegroundMixMode.ForegroundMixModeMASKPEN, Color.Green)
      'Setting region border width.
      GdViewer1.SetRegionBorderWidth(regionId, 1)
      'Setting region border color.
      GdViewer1.SetRegionBorderColor(regionId, Color.Blue)
      'Redrawing the whole image.
      GdViewer1.ClearRect()
      GdViewer1.Redraw()
   End If
End Sub
Copy Code
//We assume that GdPicture has been correctly installed and unlocked.
//We assume the GdViewer object called GdViewer1 has been created and painted on the form.
GdPictureImaging oGdPictureImaging = new GdPictureImaging();
//Loading the image from a file.
int imageId = oGdPictureImaging.CreateGdPictureImageFromFile("C:\\Image.tif");
//Checking if the image resource has been loaded correctly.
if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)
{
   MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Drawing regions Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
   //Displaying the image in the GdViewer.
   GdViewer1.DisplayFromGdPictureImage(imageId);
}
oGdPictureImaging.Dispose();

//On the Mouse UP event on the GdViewer, create a highlighted region based on the rectangle of selection of the GdViewer.
//If no rectangle of selection is painted on the GdViewer, this event will do nothing.
public void Mouse_UP_Draw_Region(System.Object eventSender, System.EventArgs eventArgs)
{
   //Initializing variables to hold the position of the rectangle of selection on the document.
   int leftArea = 0;
   int topArea = 0;
   int widthArea = 0;
   int heightArea = 0;
   //Checking if a rectangle of selection has been painted on the GdViewer.
   if (GdViewer1.IsRect())
   {
      //Getting the location of the selection on the document.
      GdViewer1.GetRectCoordinatesOnDocument(ref leftArea, ref topArea, ref widthArea, ref heightArea);
      //Setting the ROI on the document:
      //Adding a region in place of the rectangle of selection.
      int regionId = GdViewer1.AddRegion("Region", leftArea, topArea, widthArea, heightArea, GdPicture14.ForegroundMixMode.ForegroundMixModeMASKPEN, Color.Green);
      //Setting region border width.
      GdViewer1.SetRegionBorderWidth(regionId, 1);
      //Setting region border color.
      GdViewer1.SetRegionBorderColor(regionId, Color.Blue);
      //Redrawing the whole image.
      GdViewer1.ClearRect();
      GdViewer1.Redraw();
   }
}