【发布时间】:2021-01-09 01:12:04
【问题描述】:
我正在使用 C# 开发一个应用程序。在我开发的应用程序中,我使用用户选择的图片文件并将图片传输到表单中。
在这一步之后,我想对图片的位图进行更改。例如将图像调整为小尺寸并转换为 1bpp 颜色格式。
我现在可以做这些,我可以调整图像大小并将其转换为 1bpp 颜色格式,但此时我认为我有质量问题。
例如,当我截取一段文本并将其发送到程序时,当我以调整大小的 1bpp 颜色格式查看文本时,我发现文本中的字母明显不好。
我展示了我使用的算法和应用程序的屏幕截图:
Bitmap bmp = new Bitmap(ResizeImage.filePath);
Bitmap bmpOriginalRGB = Helper.ImageResize(bmp, 512, 384);
pcbox1.Image = bmpOriginalRGB;
Bitmap bmpResizeRGB = Helper.ImageResize(bmp, ResizeWidth, ResizeHeight);
pcbox2.Image = bmpResizeRGB;
Bitmap bmpResize1BPP_1 = Helper.ConvertTo1BppImage(Helper.ImageResize(bmp, ResizeWidth, ResizeHeight));
pcbox3.Image = bmpResize1BPP_1;
Bitmap bmpResize1BPP_2 = bmpResizeRGB.Clone(new Rectangle(0, 0, ResizeWidth, ResizeHeight), PixelFormat.Format1bppIndexed);
pcbox4.Image = bmpResize1BPP_2;
Bitmap oledBitmap = bmpResize1BPP_2;
和
public static Bitmap ImageResize(Image image, int width, int height)
{
var destRect = new Rectangle(0, 0, width, height);
var destImage = new Bitmap(width, height);
destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using (var graphics = Graphics.FromImage(destImage))
{
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
using (var wrapMode = new ImageAttributes())
{
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
}
}
return destImage;
}
Here's a first screenshoot
Here's a second screenshoot
Here's a third screenshoot
例如,在第二个屏幕图像中,女人的影子显示为黑色。我不想那样。我想看到更清晰的黑白图像。
你认为有可能进一步提高这个画质吗?
编辑:抱歉翻译..
【问题讨论】:
-
为什么要使用1bpp?
-
你已经发布了这个问题previous。删除和重新发布已关闭的问题违反了社区规则。不要那样做。当您的问题被关闭时,您的工作是 edit that question 解决导致其关闭的问题,然后等待社区再次对其进行评估。如果你对它进行了足够的改进,它将重新打开。
-
如果您的问题在于转换为 1bpp,您应该真正添加执行此操作的实际函数。您发布了
ImageResize一个,但没有发布ConvertTo1BppImage一个。
标签: c# image image-processing