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

请求解决Visual Basic绘图锯齿及栅格图转高分辨率问题

问题解决方案

一、解决圆弧/圆圈的锯齿问题

你代码里文字没锯齿是因为GDI+默认给文本做了抗锯齿,但图形绘制得手动开启。改下你的绘图代码,在创建Graphic_Draw_Robot之后加上抗锯齿设置:

Graphic_Draw_Robot = Graphics.FromImage(PicBox.Image)
' 添加以下两行开启图形抗锯齿
Graphic_Draw_Robot.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
Graphic_Draw_Robot.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
Graphic_Draw_Robot.Clear(Color_Back)

另外注意两个细节:

  • 别用-1调整位置(比如rect_Robot.Location = New Point(-1, -1)),这会导致图形被截断,反而加重锯齿感,直接用整数坐标定位即可
  • 绘制椭圆和圆弧时,确保矩形尺寸为整数,避免浮点运算造成的边缘模糊

二、栅格图像转高分辨率图像

方案1:绘图时直接生成高分辨率位图

不要直接按显示大小创建Bitmap,先按目标分辨率的比例放大绘制,再让控件缩放到显示:

' 比如要生成2倍分辨率的图像,先创建2倍大小的Bitmap
Dim dpiScale As Integer = 2
Graphic_Draw_Robot_BMP = New Bitmap(CInt(Size_Robot.Width * dpiScale), CInt(Size_Robot.Height * dpiScale))
' 设置Bitmap的DPI参数
Graphic_Draw_Robot_BMP.SetResolution(96 * dpiScale, 96 * dpiScale)
' 后续所有尺寸、坐标、字体大小都乘以dpiScale
Size_Robot.Width = CInt((Scale_GD * 0.8) * dpiScale)
Size_Robot.Height = CInt((Scale_GD * 0.8) * dpiScale)
' 最后将高分辨率Bitmap赋值给PictureBox,控件会自动缩放显示
PicBox.Image = Graphic_Draw_Robot_BMP
PicBox.SizeMode = PictureBoxSizeMode.Zoom

方案2:现有低分辨率图像转高分辨率

如果是已经存在的栅格图,使用插值算法放大即可:

Function UpscaleBitmap(sourceBmp As Bitmap, newWidth As Integer, newHeight As Integer) As Bitmap
    Dim result As New Bitmap(newWidth, newHeight)
    Using g As Graphics = Graphics.FromImage(result)
        g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
        g.DrawImage(sourceBmp, 0, 0, newWidth, newHeight)
    End Using
    Return result
End Function

实用搜索关键词

  • VB.NET GDI+ 抗锯齿
  • VB.NET 高分辨率位图绘制
  • GDI+ SmoothingMode AntiAlias
  • Bitmap 插值放大 VB.NET

内容的提问来源于stack exchange,提问作者Hamid Davoodi Shandiz

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 00:54:54