问题
Im drawing an image on picture box which is in stretch mode,I translate the mouse coordinates on the mouse click event by using a function to obtain the real coordinates and draw the image by overriding the on-paint event and using the paint event Graphics.
Since the picture box is set to stretch i only obtain a small size image when i try to save the image by using picturebox.DrawtoBitmap
Function.The extra parts are padded with Black colour.Please help me out.
回答1:
You can try this:
using (Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width,
pictureBox1.ClientSize.Height)) {
using (Graphics g = Graphics.FromImage(bmp)) {
g.DrawImage(yourBitmap,
new Rectangle(0, 0, bmp.Width, bmp.Height),
new Rectangle(0, 0, yourImage.Width, yourImage.Height),
GraphicsUnit.Pixel);
}
bmp.Save(@"c:\yourfile.png", ImageFormat.Png);
}
来源:https://stackoverflow.com/questions/8698865/save-image-from-user-drawn-picturebox-whose-sizemode-stretch-in-c-sharp-winforms