我在保存图片时遇到问题。使用此代码,我将两张图片放在一起。但是当我保存它们时,质量比原始图片的质量差。
Image Image1 = Image.FromFile(openFileDialogOpenPicture1.FileName);
Image Image2 = Image.FromFile(openFileDialogOpenPicture2.FileName);
int imageHeight = 0;
if (Image1.Height > Image2.Height)
imageHeight = Image1.Height;
else
imageHeight = Image2.Height;
Bitmap finalImage = new System.Drawing.Bitmap(Image1.Width + Image2.Width, imageHeight);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
{
//set background color
g.Clear(System.Drawing.Color.Black);
//go through images and draw it on the final image
int offset = 0;
g.DrawImage(pictureBoxBackground1.Image, new System.Drawing.Rectangle(offset, 0, Image1.Width, Image1.Height));
offset += Image1.Width;
g.DrawImage(pictureBoxBackground2.Image, new System.Drawing.Rectangle(offset, 0, Image2.Width, Image2.Height));
var eps = new EncoderParameters(1);
eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
var ici = GetEncoderInfo("image/jpeg");
finalImage.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\TestImage.jpg", ici, eps);
}
我也尝试保存未压缩的图片,但这只会使文件文件更大而不是质量更好。先感谢您!