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

问题描述 投票:5回答:3

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

我有这段代码,它成功地在图片框中裁剪了我的图像,但是当我尝试将其保存到数据库中时。它是空的。

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();

我该怎么办?谢谢。

c# bitmap
3个回答
4
投票

像这样:

  Bitmap bmp = new Bitmap(100,100,graphics);

0
投票

使用这样的结构:

using (Bitmap bitmap = new Bitmap(rectangle.Width, rectangle.Height))
        {
            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
               //draw image..
            }
            return bitmap;
        }

0
投票

我找到此答案作为将Graphics对象转换为Bitmap的解决方案

https://stackoverflow.com/a/48421302/12558901

© www.soinside.com 2019 - 2024. All rights reserved.