How to convert Graphics into Image or Bitmap?
I have this code and it successfully crops my image in a picturebox but when I try to save it into a database.. it's empty.
Bitmap sourceBitmap = new Bitmap(pctImage.Image, pctImage.Width, pctImage.Height);
Graphics g = frmAdd.pctImage.CreateGraphics();
Rectangle rectCropArea;
rectCropArea = new Rectangle(50, 3, 230, 240);
g.DrawImage(sourceBitmap, new Rectangle(0, 0, frmAdd.pctImage.Width, frmAdd.pctImage.Height), rectCropArea, GraphicsUnit.Pixel);
sourceBitmap.Dispose();
What should I do with this one? Thanks.
像这样:
Bitmap bmp = new Bitmap(100,100,graphics);
Use a structure like this:
using (Bitmap bitmap = new Bitmap(rectangle.Width, rectangle.Height))
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
//draw image..
}
return bitmap;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.