//画线语句
g.DrawLine(new Pen(sb.Color, width), x + width / 2, 10, x + width / 2, 40);//画出来的效果?不知道为什么高度不一样呢!?
g.DrawLine(new Pen(sb.Color, width), x + width / 2, 10, x + width / 2, 40);//画出来的效果?不知道为什么高度不一样呢!?
解决方案 »
- 请教个LINQ 查询记录的问题 两个集合查询条件交集 (详情请见内)
- 调用动态库的问题(高分)
- 窗体定时转换窗体 新手求救
- LINQ高手请进,一个动态组织LINQ查询的问题
- C#应用telnet问题
- 高分求救,如何将Form上的图片拖放到photoshop中
- C# polyfit 拟合函数实现
- 关于网页自动填表单的问题?
- 在C#中怎么实现像IE属性的那个删除cookies呀??拜托各位啦..谢谢!
- 尝试运行项目时出错: 未能加载文件或程序集“CriValuePopWin”或它的某一个依赖项。该模块应包含一个程序集清单。
- 怎么从gridview 的templatefield 中的Table 中取出一列的值。
- excel导入到datagridview太慢了,且丢失数据
楼主只给出一条线,这个问题与其他线有关。(1) 核实四个参数排列顺序,纵坐标是否相等。
x1 第一个点的 x 坐标。
y1 第一个点的 y 坐标。
x2 第二个点的 x 坐标。
y2 第二个点的 y 坐标。(2)参数类型 y1,y2 的值 是否是经过计算得到的,坐标值,float浮点型,是不准确数值,计算过程中和表示上有误差。
坐标值使用前采用相同的精度。 或最后直接转化成int32类型。这样保证值是相等的。
Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;看看
g.DrawLine(new Pen(sb.Color, width), x + width / 2, 10, x + width / 2, 40); 就是这一语句呀!其它的代码就是计算width的的值的
width:是保留二位的小数的!
{
g.DrawLine(new Pen(Color.Black, 2), width , 10, width, 40);
}没有出现你的这种现象
g.FillRectangle(myBrush, new RectangleF( 3, 1, 1, 100));
g.FillRectangle(myBrush, new RectangleF( 6, 1, 2, 100));
g.FillRectangle(myBrush, new RectangleF(11, 1, 3, 100));
g.FillRectangle(myBrush, new RectangleF(20, 1, 2, 100));
g.FillRectangle(myBrush, new RectangleF(25, 1, 5, 100));
如果是,条形码本来都是有长有短的,多出来的地方可能是其他地方画的你都定死了 10-40 int x = 0;
float width = 10.99F;
e.Graphics.DrawLine(new Pen(Brushes .Red,width) , x + width / 2, 10, x + width / 2, 40); x = 12;
width = 20.99F;
e.Graphics.DrawLine(new Pen(Brushes.Red, width), x + width / 2, 10, x + width / 2, 40); x = 34;
width = 30.99F;
e.Graphics.DrawLine(new Pen(Brushes.Red, width), x + width / 2, 10, x + width / 2, 40);
计算好第一个的Height后,其他都是用这个.
的确,企业用的打印机输出最小单位是一像素.FillRectangle精度够用了.
有什么办法可以提高精度的?” 应该是另一个问题吧.你已经确认是精度不够吗?不会是别的原因?
不过楼主也有误导嫌疑, 问题问的也忒模糊了
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e); Graphics g = e.Graphics; for (int i = 0; i < 100; i += 5)
{
float width = i / 20.0f;
if (width > 2.0f) {
width = 2.0f;
}
g.DrawLine(new Pen(Color.Black, width), (float)i , (float)10, (float)i, (float)80);
}
for (int i = 0; i < 100; i += 5) {
float width = i / 20.0f;
if (width > 2.0f) {
width = 2.0f;
}
g.FillRectangle(new SolidBrush(Color.Black), (float)i, (float)100, width, (float)80);
}
}试了下, FillRectangle 精度比 DrawLine 精度高点