簡體   English   中英

如何將圖形轉換為圖像或位圖?

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

如何將圖形轉換為圖像或位圖?

我有這個代碼,它成功地在圖片框中裁剪了我的圖像,但是當我嘗試將它保存到數據庫中時..它是空的。

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

我該怎么辦? 謝謝。

像這樣:

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

使用這樣的結構:

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