简体   繁体   English

如何将图形转换为图像或位图?

[英]How to convert Graphics into Image or Bitmap?

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;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM