fre*_*uin 12 c# wpf image bitmap blurry
我正在寻找一种方法来阻止WPF模糊我的图像.我希望我的应用程序在高DPI显示器上看起来很好,所以我创建了96x96px的图标以显示大小为32x32.
google中有很多内容可供查找,甚至在stackoverflow上也有一些关于此的主题.总结他们说:启用属性UseLayoutRounding并设置RenderOptions.BitmapScalingMode为HighQuality.不幸的是,这对我来说并不适用 - 图像看起来仍然非常模糊.然后我在具有更高DPI aaaand-WOW的笔记本电脑上测试了我的应用程序.图像非常清晰.
我唯一的解决方案是创建一个自定义控件,将ImageSource转换为System.Drawing.Bitmap,在那里重新调整它以匹配图像尺寸并将其转换回WPF ImageSource.显然不是完美的解决方案!
 

所以问题是:为什么在低dpi显示屏上看我的图像模糊?我不知道是什么导致了这一点,希望somone有一个想法来解决这个问题.
这里有一些我发现的最有用的资源:
编辑:
这里要求的是转换ImageSource的代码.有一些方法调用没有包括在内,但你可以通过谷歌快速找到它们.
// Calculate the conversion factor.
float dpi = WpfImageHelper.GetCurrentDPI(this);
float factor = dpi / 96f;
int width = (int)Math.Round(this.image.ActualWidth * factor);
int height = (int)Math.Round(this.image.ActualHeight * factor);
// Create bitmaps.
Bitmap oldBitmap = WpfImageHelper.ToWinFormsBitmap2((BitmapSource)this.Source);
Bitmap newBitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
// Draw the new bitmap. Use high-quality interpolation mode.
using (Graphics g = Graphics.FromImage(newBitmap))
{
    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
    g.Clear(System.Drawing.Color.Transparent);
    g.DrawImage(oldBitmap, 0, 0, newBitmap.Width, newBitmap.Height);
}
// Set the image source to the resized bitmap.
this.Source = WpfImageHelper.ToWpfBitmap2(newBitmap); 
小智 3
你的图标是位图,所以恕我直言,你不会解决这个问题。您需要寻找不同的解决方案。您希望图标与设备无关,因此需要将图像转换为矢量或将图像转换为 xaml。这个问题之前已经被问过并回答过,解决方案不需要太多努力。
| 归档时间: | 
 | 
| 查看次数: | 2180 次 | 
| 最近记录: |