Highlight and crop an image in VB.NET
This example shows how to create an image from the area defined by a highlighted region located on top of a document displayed within the GdViewer
object. Highlighted regions can be used to specify areas and highlight them using only the mouse.
'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 currentImageID 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(currentImageID)End If'We will keep the current image for further use, see below.
Dim selectedImageID As Integer = 0 'A new image we are going to create.'On the Mouse UP event on the GdViewer, get a highlighted region coordinates 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) 'Creating the image from the highlighted region. selectedImageID = oGdPictureImaging.CreateClonedGdPictureImageArea(currentImageID, leftArea, topArea, widthArea, heightArea) GdViewer1.DisplayFromGdPictureImage(selectedImageID) End IfEnd Sub
'Do not forget to release and dispose both images!oGdPictureImaging.ReleaseGdPictureImage(currentImageID);oGdPictureImaging.ReleaseGdPictureImage(selectedImageID);oGdPictureImaging.Dispose();
This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.