GdPicture.NET Reference Guide
CopyRegionToGdPictureImage Method (GdViewer)
Example 





GdPicture14.WPF Namespace > GdViewer Class : CopyRegionToGdPictureImage Method
The horizontal (X) coordinate (0-based) of the top left point, in pixels, of the copied region's rectangle, related to the current page.
The vertical (Y) coordinate (0-based) of the top left point, in pixels, of the copied region's rectangle, related to the current page.
The width, in pixels, of the region's rectangle.
The height, in pixels, of the region's rectangle.
Copies the content of the specified region, related to the current page of the document displayed in the GdViewer control, into a GdPictureImage object. Please ensure, that specified coordinates and dimensions correspond to the actual document pages area of the currently displayed page.

The method creates a new GdPictureImage object of the required area on the displayed page. The resulting image is recognizable by its unique image identifier. Please note that you have to release the created image from the memory using the ReleaseGdPictureImage method.

Syntax
'Declaration
 
Public Function CopyRegionToGdPictureImage( _
   ByVal Left As Integer, _
   ByVal Top As Integer, _
   ByVal Width As Integer, _
   ByVal Height As Integer _
) As Integer
public int CopyRegionToGdPictureImage( 
   int Left,
   int Top,
   int Width,
   int Height
)
public function CopyRegionToGdPictureImage( 
    Left: Integer;
    Top: Integer;
    Width: Integer;
    Height: Integer
): Integer; 
public function CopyRegionToGdPictureImage( 
   Left : int,
   Top : int,
   Width : int,
   Height : int
) : int;
public: int CopyRegionToGdPictureImage( 
   int Left,
   int Top,
   int Width,
   int Height
) 
public:
int CopyRegionToGdPictureImage( 
   int Left,
   int Top,
   int Width,
   int Height
) 

Parameters

Left
The horizontal (X) coordinate (0-based) of the top left point, in pixels, of the copied region's rectangle, related to the current page.
Top
The vertical (Y) coordinate (0-based) of the top left point, in pixels, of the copied region's rectangle, related to the current page.
Width
The width, in pixels, of the region's rectangle.
Height
The height, in pixels, of the region's rectangle.

Return Value

A unique image identifier of the newly created image referring to an associated GdPictureImage object. Please always use the GetStat method to determine if this method has been successful.

Just to remind you that you need to release the image from the memory using the ReleaseGdPictureImage method after being used.

Remarks
We strongly recommend using the GetStat method to identify the specific reason for the method's failure.

Please note that this method expects to have a core GdPicture license to be unlocked.

Example
How to create an image from the content of the visible area of the current page.
'We assume that the GdViewer1 control has been properly integrated.
If GdViewer1.DisplayFromFile("") = GdPictureStatus.OK Then
    Dim left As Double = 0, top As Double = 0, width As Double = 0, height As Double = 0
    GdViewer1.GetDisplayedArea(left, top, width, height)
    Dim imageID As Integer = GdViewer1.CopyRegionToGdPictureImage(CInt(left), CInt(top), CInt(width), CInt(height))
    If GdViewer1.GetStat() = GdPictureStatus.OK Then
        Using oImage As GdPictureImaging = New GdPictureImaging()
            If oImage.SaveAsJPEG(imageID, "visible_region.jpg") = GdPictureStatus.OK Then
                MessageBox.Show("Done!", "GdViewer.CopyRegionToGdPictureImage")
            Else
                MessageBox.Show("The image can't be saved. Status: " + oImage.GetStat().ToString(), "GdViewer.CopyRegionToGdPictureImage")
            End If
        End Using
        GdViewer1.ReleaseGdPictureImage(imageID)
    Else
        MessageBox.Show("The image can't be created. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.CopyRegionToGdPictureImage")
    End If
Else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.CopyRegionToGdPictureImage")
End If
//We assume that the GdViewer1 control has been properly integrated.
if (GdViewer1.DisplayFromFile("") == GdPictureStatus.OK)
{
    double left = 0, top = 0, width = 0, height = 0;
    GdViewer1.GetDisplayedArea(ref left, ref top, ref width, ref height);
    int imageID = GdViewer1.CopyRegionToGdPictureImage((int)left, (int)top, (int)width, (int)height);
    if (GdViewer1.GetStat() == GdPictureStatus.OK)
    {
        using (GdPictureImaging oImage = new GdPictureImaging())
        {
            if (oImage.SaveAsJPEG(imageID, "visible_region.jpg") == GdPictureStatus.OK)
                MessageBox.Show("Done!", "GdViewer.CopyRegionToGdPictureImage");
            else
                MessageBox.Show("The image can't be saved. Status: " + oImage.GetStat().ToString(), "GdViewer.CopyRegionToGdPictureImage");
        }
        GdViewer1.ReleaseGdPictureImage(imageID);
    }
    else MessageBox.Show("The image can't be created. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.CopyRegionToGdPictureImage");
}
else
    MessageBox.Show("The file can't be displayed. Status: " + GdViewer1.GetStat().ToString(), "GdViewer.CopyRegionToGdPictureImage");
See Also

Reference

GdViewer Class
GdViewer Members
CopyToClipboard Method
CopyRegionToClipboard Method
PagePixelWidth Property
PagePixelHeight Property
GetDisplayedArea Method
ReleaseGdPictureImage Method