从 PictureBox 保存原始图像,未调整大小

问题描述 投票:0回答:2

是否可以从 PictureBox 中保存原始质量的原始图像,而不是拉伸/调整大小的图像?我从服务器下载字节数组并将其放入 PictureBox 中,我希望用户能够保存实际图像,但它应该是我从 HTTP 服务器收到的原始图像(原始质量和原始大小),而不是调整大小和缩小我在图片框中展示的质量。是否可能或者我必须将从服务器收到的字节数组存储在某处才能实现此目的?

c# .net winforms picturebox
2个回答
0
投票

Image
PictureBox
属性包含原始图像,而控件可以根据其
SizeMode
将图像绘制为缩放/调整大小/拉伸。您可以在here查看该属性的源代码。 只需保存
Image
属性,它将与您从数据库中读取的图像相同。

所以打电话

pictureBox1.Image.Save
就足够了。


0
投票

使用

pictureBox.Image.Save
的问题是它不会保存背景。所以我最终使用:

 //create a Bitmap from the pictureBox1 background Image:
  using Bitmap saveBMP = new Bitmap(pictureBox1.BackgroundImage);

 // create a new Graphics instance to draw on:
  using (Graphics g = Graphics.FromImage(saveBMP))

 // fill in bitmap from pictureBox's Image layer
  g.DrawImage(pictureBox1.Image,0,0); 

 // and finally, save it off:
  saveBMP.Save(saveImage.FileName);

希望这能让你保持理智——我花了一些功夫才把它弄好!

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