When we select the area with ViewerMouseMode.MouseModeAreaSelection then draw the image within it with Drawimage() method in gdpicturepdf...
But if image size is less than the selection area then the selection area should be resized within that image..
And if we draw image then it is float through the document with drawimage method in gdpicturepdf ..
For this, anybody has idea just reply me asap.
Here is my code..
Code: Select all
private void btnDropImage2_Click(object sender, EventArgs e)
{
GdViewer1.MouseMode = GdPicture.ViewerMouseMode.MouseModeAreaSelection;
}
private void GdViewer1_MouseUp(object sender, MouseEventArgs e)
{
if (GdViewer1.IsRect())
{
GdViewer1.GetRectCoordinatesOnDocumentInches(ref t_left, ref t_top, ref t_width, ref t_height);
GdPicturePDF oGdPicturePDF = new GdPicturePDF();
GdPictureImaging oGdPictureImaging = new GdPictureImaging();
oGdPicturePDF.LoadFromFile(path, true);
//GdViewer1.DisplayFromGdPicturePDF(oGdPicturePDF);
openFileDialog1.Filter = "PNG|*.png|TIFF Image|*.tif|JPEG|*.jpg";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string Imagepath = openFileDialog1.FileName;
int ImageID = oGdPictureImaging.CreateGdPictureImageFromFile(Imagepath);
float width = oGdPictureImaging.GetWidth(ImageID) / 72; ;
float height = oGdPictureImaging.GetHeight(ImageID) / 72; ;
if (ImageID > 0)
{
bool h = oGdPicturePDF.SelectPage(GdViewer1.CurrentPage);
float pageWidth = oGdPicturePDF.GetPageWidth();
float pageHeight = oGdPicturePDF.GetPageHeight();
oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitInch);
oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
string imageResName = oGdPicturePDF.AddImageFromGdPictureImage(ImageID, false, false);
oGdPictureImaging.ReleaseGdPictureImage(ImageID);
oGdPicturePDF.DrawImage(imageResName, t_left, t_top + t_height, width, height);
DialogResult message = MessageBox.Show("Is This Correct?", "", MessageBoxButtons.YesNoCancel);
if (message == DialogResult.Yes)
{
GdViewer1.CloseDocument();
oGdPicturePDF.SaveToFile(path);
GdViewer1.DisplayFromFile(path);
}
else if(message == DialogResult.No)
{
}
else if(message == DialogResult.Cancel)
{
}
}
}
}
}