微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vb.net – 圆角矩形不准确

我发现使用GDI绘制圆角矩形的每个示例代码都是这样的(从BobPowell.net解除并略微修改):
Private Sub Panel1_Paint(ByVal sender As Object,ByVal e As PaintEventArgs) Handles Panel1.Paint
    e.Graphics.Clear(SystemColors.Window)
    e.Graphics.SmoothingMode = SmoothingMode.None

    Call DrawRoundRect(e.Graphics,Pens.Red,10,48,24,6)
  End Sub

  Public Sub DrawRoundRect(ByVal g As Graphics,ByVal p As Pen,ByVal x As Single,ByVal y As Single,ByVal width As Single,ByVal height As Single,ByVal radius As Single)
    Using gp As New GraphicsPath()
      gp.Startfigure()
      gp.AddArc(x + width - radius,y,radius * 2,270,90)
      gp.AddArc(x + width - radius,y + height - radius,90)
      gp.AddArc(x,90,180,90)
      gp.Closefigure()
      g.DrawPath(p,gp)
    End Using
  End Sub

这会产生一个圆角矩形,其中只有左上角是准确的.

AntiAliasing必须关闭,因为它正在通过远程桌面连接,我不能依赖它可用.此外,我正在寻找一个清晰的圆角矩形.

我已经尝试调整其他角落的大小并更改笔对齐,但似乎没有任何东西可以产生简单,精确的圆角矩形.

有没有办法在旧的winforms中绘制比这更好的圆角矩形?

1)将源图像的大小调整为其原始大小的二进制倍数.通常,我将重新采样到比原始宽度和高度大4倍(或8或16)的宽度和高度.

2)执行我的所有GDI绘图操作(当然,考虑到我的坐标需要乘以4倍).没有必要使用任何花哨的抗锯齿.

3)将图像重新采样回原始尺寸.缩小图像会产生良好的平滑效果,并最大限度地减少线条,曲线等中的任何舍入误差.

private Bitmap GenerateButton(int overSampling) {

    int overSampling = 8;
    int width=(48 + 10 + 10 + 6) * overSampling;
    int height=(24 + 10 + 10 + 6) * overSampling;

    // Draw the button with the rounded corners,but do
    // so at 8 times the normal size.
    Bitmap bitmap=new Bitmap(width,height);
    using (Graphics g = Graphics.FromImage(bitmap)) {
        g.Clear(Color.White);
        g.SmoothingMode = SmoothingMode.None;
        DrawRoundRect(overSampling,g,new Pen(Color.Red,overSampling),6);
    }

    // Shrink the image down to its intended size
    Bitmap shrunkVersion=new Bitmap(bitmap.Width / overSampling,bitmap.Height / overSampling);
    using (Graphics g = Graphics.FromImage(shrunkVersion)) {
        // Use hi-quality resampling for a nice,smooth image.
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        g.DrawImage(bitmap,shrunkVersion.Width,shrunkVersion.Height);
    }

    return shrunkVersion;
}

private void DrawRoundRect(int overSampling,Graphics g,Pen p,float x,float y,float width,float height,float radius)
{
    using (GraphicsPath gp = new GraphicsPath())
    {
        gp.Startfigure();
        gp.AddArc((x + width - radius) * overSampling,y * overSampling,(radius * 2) * overSampling,90);
        gp.AddArc((x + width - radius) * overSampling,(y + height - radius) * overSampling,90);
        gp.AddArc(x * overSampling,radius * 2 * overSampling,90);
        gp.Closefigure();
        g.DrawPath(p,gp);
    }
}

没有过采样:

进行8次过采样:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强制返回为文本 -------------------------------- 数字类型的格式化 --------------------------------     固定格式参数:     General Number 普通数字,如可以用来去掉千位分隔号     format$("100,1
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办法, Format 或者FormatDateTime 竟然结果和系统设置的区域语言的日期和时间格式相关。意思是尽管你用诸如 Format(Now, "MM/dd/yyyy"),如果系统的设置格式区域语言的日期和时间格式分隔符是"-",那他还会显示为 MM-dd-yyyy     只有拼凑: <%response.write
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace My ‘全局错误处理,新的解决方案直接添加本ApplicationEvents.vb 到工程即可 ‘添加后还需要一个From用来显示错误。如果到这步还不会则需要先打好基础啦 ‘======================================================== ‘以下事件
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用的爽呀,这篇文章写与2011年,看来我以前没有认真去找这个方法呀。 https://blog.csdn.net/chzjxgd/article/details/6176325 金蝶K3 BOS的插件官方是用VB6编写的,如果  能用.Net下的语言工具开发BOS插件是一件很愉快的事情,其中缘由不言而喻,而本文则是个人首创,实现在了用V
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理 Dim m As Range, tmpStr As String, s As String Dim x As Integer, y As Integer, subStr As String If MsgBox("确定要分列处理吗?请确定分列的数据会覆盖它后面的单元格!", _
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) 2 Dim path As String, hash As String 3 For Each fil
  Imports MySql.Data.MySqlClient Public Class Form1 ‘ GLOBAL DECLARATIONS Dim conString As String = "Server=localhost;Database=net2;Uid=root;Pwd=123456;" Dim con As New MySqlConnection
‘導入命名空間 Imports ADODB Imports Microsoft.Office.Interop   Private Sub A1() Dim Sql As String Dim Cnn As New ADODB.Connection Dim Rs As New ADODB.Recordset Dim S As String   S = "Provider=OraOLEDB.Oracl
Imports System.IO Imports System.Threading Imports System.Diagnostics Public Class Form1 Dim A(254) As String    Function ping(ByVal IP As Integer) As String Dim IPAddress As String IPAddress = "10.0.
VB运行EXE程序,并等待其运行结束 参考:https://blog.csdn.net/useway/article/details/5494084 Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Pr