在 C# 中调整单色图像的大小
我有以下代码可以使用以下代码调整单色图像的大小(因此像素值为 0[黑色] 或 255[白色])
Bitmap ResizedCharImage = new Bitmap(newwidth, newheight);
using (Graphics g = Graphics.FromImage((Image)ResizedCharImage))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(CharBitmap, new Rectangle(0, 0, newwidth, newheight),
new Rectangle(0, 0, CharBitmap.Width, CharBitmap.Height), GraphicsUnit.Pixel);
}
我遇到的问题是在调整大小(我放大图像)后某些像素值变成 254、253、1、2 等。(因此不是单色的。)我需要这种情况不会发生。这可能吗,也许可以通过更改 Graphins 属性之一来实现?
I have the following code to resize a monochromatic image (hence pixel value is 0[black] or 255[white]) with the following code
Bitmap ResizedCharImage = new Bitmap(newwidth, newheight);
using (Graphics g = Graphics.FromImage((Image)ResizedCharImage))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(CharBitmap, new Rectangle(0, 0, newwidth, newheight),
new Rectangle(0, 0, CharBitmap.Width, CharBitmap.Height), GraphicsUnit.Pixel);
}
The problem that I am having is that after resizing (i am enlarging the image) some of the pixel values become 254, 253, 1, 2 etc. (and so are not monochromatic.) I need that this do not occur. Is this possible, maybe by changing one of the Graphins properties?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然通过将 InterpolationMode 设置为解决了问题
apparently problem solved by setting InterpolationMode to
使用SmoothingMode.None
Use
SmoothingMode.None