Situation: i have a bitmap loadedImage1 which the user is able to resize, and move around inside picturebox1.
objective: this loadedImage1 is then to be added to a pdf document (which is working) but needs to be using the current size and location(as the user can move it around)
atm: the picture gets added, but the image is resized to fit the control, so the user's movement and resizing is ignored.
picturebox_double click looks like
// load image to image object
loadedImage1 = Image.FromFile(openFD.FileName);
// set initial rectangle bounds for image
imageBounds1 = new System.Drawing.Rectangle(new Point(), loadedImage1.Size);
// refresh the picture box to show new image
pictureBox1.Refresh();
pictureBox1.BackgroundImage = null;
mouse down and move are:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
// test if mouse click inside image bounds
this.imageClicked = imageBounds1.Contains(e.Location);
// capture relative position of mouse to Top,Left of image
this.SizeOfImageOffset1 = (Size)imageBounds1.Location - (Size)e.Location;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
// if image was clicked and mouse is captured
if (imageClicked && pictureBox1.Capture)
{
Cursor.Current = Cursors.NoMove2D;
// set new location for image based on relative mouse position
imageBounds1.Location = (Point)(SizeOfImageOffset1 + (Size)e.Location);
// force re-paint of picture box
pictureBox1.Refresh();
}
}
and paint method is just
e.Graphics.DrawImage(loadedImage1, imageBounds1);
i just need to caputre loadedImage1 using its current x, y, width, height..
it should be simple, but i'm stuck...
i add it to the pdf using abcpdf 7, code:
units are in "mm".
myDoc.Rect.SetRect(10, 240, 92, 75);
myDoc.AddImageBitmap((Bitmap)pictureBox2.BackgroundImage, true);
any tips would be great. thanks alot!