我有一张分辨率为6000x4000的PNG图像,我必须借助它。所以我把图片加载到1280x800大小的图片框中。绘制完成后,我需要将PNG图像保存为原始分辨率6000x4000。所以我将其重新装入尺寸6000x4000的新位图使用在WinForms中将调整大小后的位图图像调回原始大小
btm = new Bitmap(6000, 4000);
image = Graphics.FromImage(btm);
g.DrawImage(btm, Point.Empty);
而且使用
btm.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
现在我结束了6000x4000分辨率的白色背景png图片,但用的编辑后的图像进行保存1280x800就像这样Saved Image
如何将图像调整为其原始大小(6000x4000)。谢谢。
也请找我codebelow
private void drawImage(string imgLocation)
{
Bitmap b = new Bitmap(imgLocation);
////test
pictureBox1.Height = 800;
pictureBox1.Width = 1280;
g = pictureBox1.CreateGraphics();
btm = new Bitmap(6000, 4000);
image = Graphics.FromImage(btm);
image.CompositingMode = CompositingMode.SourceCopy;
image.CompositingQuality = CompositingQuality.HighQuality;
image.InterpolationMode = InterpolationMode.HighQualityBicubic;
image.SmoothingMode = SmoothingMode.HighQuality;
image.PixelOffsetMode = PixelOffsetMode.HighQuality;
image.Clear(Color.White);
image.DrawImage(b, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
//image.DrawImage(btm, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
//g.DrawImage(btm, Point.Empty);
g.DrawImage(btm, new Rectangle(0, 0, 6000,4000));
}
这应该很简单。 DrawImage有许多重载。其中一些允许指定目的地大小。 –
谢谢,我会研究它。如果可能,你能否提供一些例子来达到这个目的? – SwamJay
** 1)**如果你打电话给'CreateGraphics()',你做错了。 ** 2)**在绘制时缩放位图,只需设置Graphics对象的变换或使用“DrawImage()”重载,以便指定图形的目标矩形。 ** 3)**你发布的代码很奇怪,除了调用'CreateGraphics()';你把'b'绘制成'btm',但是你试图在'PictureBox'控件上画'btm'? ** 4)**如果您想要一个很好的答案,您需要提供一个良好的[mcve],可以可靠地再现您的问题。 –