簡體   English   中英

從用戶繪制的PictureBox保存圖像,該用戶的PictureMode在C#winforms中為SizeMode = stretch

[英]Save Image from user Drawn PictureBox whose SizeMode=stretch in C# winforms

我在處於拉伸模式的圖片框上繪制圖像,我通過使用獲取真實坐標的函數來轉換鼠標單擊事件上的鼠標坐標,並通過覆蓋on-paint事件和使用paint事件Graphics來繪制圖像。 由於將圖片框設置為拉伸,因此當我嘗試使用picturebox.DrawtoBitmap函數保存圖像時,只能獲得較小尺寸的圖像。多余的部分用黑色填充。請幫幫我。

您可以嘗試以下方法:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM