You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

低分辨率屏幕下WPF中System.Drawing绘制的Bitmap预览模糊问题

问题描述

使用System.Drawing.Graphics绘制用于打印预览的Bitmap时,在低分辨率屏幕(或修改系统分辨率后)显示模糊;但在1920*1080等高分辨率下显示正常。

XAML代码
<Border BorderBrush="Gray"
     BorderThickness="1"
     Margin="5"
     DockPanel.Dock="Top">
     <ScrollViewer VerticalScrollBarVisibility="Auto"
                   Width="300"
                   BorderThickness="0">
                   <Border Padding="20">
                       <Image Source="{Binding ImageSource}" />
                   </Border>
     </ScrollViewer>
 </Border>
ViewModel代码
var height = CalculateHeight();

var bitmap = new Bitmap(previewWidth, height);
using (var g = Graphics.FromImage(bitmap))
{
     _printService.PrintSalesOrder(g, Order, new Rectangle
     {
          X = 0,
          Y = 0,
          Width = previewWidth,
          Height = height
     });
}

_hBitMap = bitmap.GetHbitmap();

var bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
      _hBitMap, // you will need to delete this hbitmap
      IntPtr.Zero,
      Int32Rect.Empty,
      BitmapSizeOptions.FromWidthAndHeight(previewWidth, height));

ImageSource = bitmapSource;
已尝试但无效的方案
  • 在MainWindow中设置UseLayoutRounding="True"
  • 在Image元素中设置RenderOptions.BitmapScalingMode="NearestNeighbor"
  • 补充:尝试了设置RenderOptions.BitmapScalingMode="Fant",问题仍未解决

内容的提问来源于stack exchange,提问作者mamado

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 18:24:26