We have had many requests and questions about how to create a new image from a selection made by the user via the mouse.
Well, it is very simple, and we shall show you how here in this tutorial.
WHAT WE NEED:
1. A GdViewer called m_GdViewer
2. A GdPictureImaging Object called m_Imaging .
3. An Image loaded to the GdViewer, let us call it m_CurrentImage.
4. An Image to store the selected area in, let us call it m_SelectionImage
Ok, now first is first, we have to make sure that a user has made a selection to the Image on the GdViewer, for that we have a function:
Code: Select all
m_GdViewer.IsRect()
Now, we need to create the parameters in which we will store the values of the location of the rectangle:
Code: Select all
int nLeft = 0, nTop = 0, nWidth = 0, nHeight = 0;
The function is:
Code: Select all
m_GdViewer.GetRectCoordinatesOnDocument(ref nLeft, ref nTop, ref nWidth, ref nHeight);
Code: Select all
int m_SelectionImage= m_Imaging.CreateClonedGdPictureImageArea(m_CurrentImage, nLeft, nTop, nWidth, nHeight);
Code: Select all
m_GdViewer.DisplayFromGdPictureImage(m_SelectionImage);
Code: Select all
//We load the first image
m_CurrentImage = m_Imaging.CreateGdPictureImageFromFile("");
m_GdViewer.DisplayFromGdPictureImage(m_CurrentImage);
//You should have this code either on a Mouse_Up event, or in a button_Clicked event if the button is a crop button
if( m_GdViewer.IsRect())
{
int nLeft = 0, nTop = 0, nWidth = 0, nHeight = 0;
m_GdViewer.GetRectCoordinatesOnDocument(ref nLeft, ref nTop, ref nWidth, ref nHeight);
int m_SelectionImage= m_Imaging.CreateClonedGdPictureImageArea(m_CurrentImage, nLeft, nTop, nWidth, nHeight);
m_GdViewer.DisplayFromGdPictureImage(m_SelectionImage);
}
Best Regards,
Sami