Graphics.FromImage和DrawImage [英] Graphics.FromImage and DrawImage

查看:231
本文介绍了Graphics.FromImage和DrawImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写这个示例代码,以便生成的图像与原始图像完全相同。



I need to write this sample code so that the resulting image is the exact same as the original.

Dim a = New Bitmap( _
 My.Application.Info.DirectoryPath & "\a.png")
 Dim b As New Bitmap(a.Width, a.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb )
 Dim g As Graphics = Graphics.FromImage(b)
 g.DrawImage(a, b.GetBounds(GraphicsUnit.Pixel))
 PictureBox1.Image = b
 b.Save("b.png", System.Drawing.Imaging.ImageFormat.Png)
 g.Dispose()



我不明白会发生什么当我将图像转换为图形时。 Image.FromFile保留所有图片数据,但图形会改变图片大小,以便g.DrawImage(a,0,0)可以是更大的图片,但会裁剪为原始图片的大小。 Graphics.FromImage会调整图片大小,因此会丢失一些质量。



这可以重写,以便结果与原始结果相同(不会调整大小/丢失质量) )?


I don''t understand what happens when I convert an image to graphics. Image.FromFile preserves all of the picture data, but graphics changes the picture size so that g.DrawImage(a, 0, 0) would be a larger picture, but cropped to the original''s size. Graphics.FromImage resizes the picture and so some quality is lost.

Can this be rewritten so that the result is the same as the original (no resizing/loss of quality)?

推荐答案

你需要经过很多代码来做一些非常简单的事情。



You''re going through a lot of code to do something very simple.

Dim b As New Bitmap(a)





尝试阅读Bitmap类的文档并查看构造函数的重载。



Try reading the documentation on the Bitmap class and look at the overloads for the constructor.


这篇关于Graphics.FromImage和DrawImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆