drawString 出现黑边 怎么解决

freezing2616 2010-12-30 07:02:39
如题
是用了bitmap以后出现的, 很费解!求大侠帮忙
...全文
474 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangpei2011 2010-12-31
  • 打赏
  • 举报
回复
好多强人
dylike 2010-12-31
  • 打赏
  • 举报
回复
在DrawString前设置文字渲染,如果不想有毛刺边缘可以任选一种:

'最高清晰度,不同显示模式或许会有些许毛刺
G.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit

'最基本的点阵模式,不会出现毛刺,但字形效果也差
G.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixel
freezing2616 2010-12-30
  • 打赏
  • 举报
回复

private void drawPicture(Graphics aGraphics)
{
bool today = false;
int y = Convert.ToInt32(t.Year);
int m = Convert.ToInt32(t.Month);
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
int first = 0;
GraphicsPath firstPath = new GraphicsPath();
Point[] firstArr = new Point[4];
firstArr[0] = new Point(20, 10);
firstArr[1] = new Point(20 + with * 7, 10);
firstArr[2] = new Point(20 + with * 7, 10 + 30);
firstArr[3] = new Point(20, 10 + 30);
firstPath.AddLines(firstArr);
aGraphics.FillPath(Brushes.LightBlue, firstPath);
Point[] pntArr = new Point[4];
GraphicsPath secondPath = new GraphicsPath();
pntArr[0] = new Point(20 + with * 5, 10 + 30);
pntArr[1] = new Point(20 + with * 7, 10 + 30);
pntArr[2] = new Point(20 + with * 7, 10 + 30 + height * 6);
pntArr[3] = new Point(20 + with * 5, 10 + 30 + height * 6);
secondPath.AddLines(pntArr);
aGraphics.FillPath(Brushes.AliceBlue, secondPath);

if (count > 0)
{
first = findFirstDayCrossForwardOneMonth(ref m, ref y);
}
else if (count < 0)
{
first = findFirstDayCrossBackwardOneMonth(ref m, ref y);
}
else
{
first = findFirstDayOfCurrentMonth();
today = true;
}

drawAssignmentsOrTests(first, m, y, aGraphics); //draw assginments and tests
aGraphics.DrawString(y.ToString(), textMonth, new SolidBrush(Color.AliceBlue), new PointF(20 + with + 10, 10 + 35));//draw year
aGraphics.DrawString(getMonth(m), textMonth, new SolidBrush(Color.White), new PointF(20 + with * 6 + 10, 10 + 20), drawFormat); //draw month
drawTable(aGraphics); //draw table
drawMonth(first, getTotalDaysOfMonth(m, y), aGraphics);
if (today == true)
{
drawToday(first, aGraphics);
}
aGraphics.Dispose();
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
bmp = new Bitmap(1100, 600);
Graphics g = Graphics.FromImage(bmp);
drawPicture(g);
CreateGraphics().DrawImage(bmp, 0, 0);
}
private void drawTable(Graphics g)
{
g.DrawLine(Pens.Black, new Point(20, 10), new Point(20 + with * 7, 10));
g.DrawLine(Pens.Black, new Point(20, 10 + 30), new Point(20 + with * 7, 10 + 30));
for (int i = 1; i <= 6; i++) //row
{
g.DrawLine(Pens.Black, new Point(20, 10 + 30 + height * i), new Point(20 + with * 7, 10 + 30 + height * i));
}
for (int i = 0; i < 8; i++) //column
{
g.DrawLine(Pens.Black, new Point(20 + with * i, 10), new Point(20 + with * i, 10 + 30 + height * 6));
}
for (int i = 0; i < 7; i++) //day
{
g.DrawString(day[i], head, new SolidBrush(Color.White), new PointF(20 + 20 + with * i, 15));
}
}
freezing2616 2010-12-30
  • 打赏
  • 举报
回复
谢二位了 代码是画一个日历
可能关键的就是这几部分吧 反正没用bimap的时候一点问题都没有 用了以后字就有边了

private void drawPicture(Graphics aGraphics)
{
bool today = false;
int y = Convert.ToInt32(t.Year);
int m = Convert.ToInt32(t.Month);
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
int first = 0;
GraphicsPath firstPath = new GraphicsPath();
Point[] firstArr = new Point[4];
firstArr[0] = new Point(20, 10);
firstArr[1] = new Point(20 + with * 7, 10);
firstArr[2] = new Point(20 + with * 7, 10 + 30);
firstArr[3] = new Point(20, 10 + 30);
firstPath.AddLines(firstArr);
aGraphics.FillPath(Brushes.LightBlue, firstPath);
Point[] pntArr = new Point[4];
GraphicsPath secondPath = new GraphicsPath();
pntArr[0] = new Point(20 + with * 5, 10 + 30);
pntArr[1] = new Point(20 + with * 7, 10 + 30);
pntArr[2] = new Point(20 + with * 7, 10 + 30 + height * 6);
pntArr[3] = new Point(20 + with * 5, 10 + 30 + height * 6);
secondPath.AddLines(pntArr);
aGraphics.FillPath(Brushes.AliceBlue, secondPath);

if (count > 0)
{
first = findFirstDayCrossForwardOneMonth(ref m, ref y);
}
else if (count < 0)
{
first = findFirstDayCrossBackwardOneMonth(ref m, ref y);
}
else
{
first = findFirstDayOfCurrentMonth();
today = true;
}

drawAssignmentsOrTests(first, m, y, aGraphics); //draw assginments and tests
aGraphics.DrawString(y.ToString(), textMonth, new SolidBrush(Color.AliceBlue), new PointF(20 + with + 10, 10 + 35));//draw year
aGraphics.DrawString(getMonth(m), textMonth, new SolidBrush(Color.White), new PointF(20 + with * 6 + 10, 10 + 20), drawFormat); //draw month
drawTable(aGraphics); //draw table
drawMonth(first, getTotalDaysOfMonth(m, y), aGraphics);
if (today == true)
{
drawToday(first, aGraphics);
}
aGraphics.Dispose();
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
bmp = new Bitmap(1100, 600);
Graphics g = Graphics.FromImage(bmp);
drawPicture(g);
CreateGraphics().DrawImage(bmp, 0, 0);
}
private void drawTable(Graphics g)
{
g.DrawLine(Pens.Black, new Point(20, 10), new Point(20 + with * 7, 10));
g.DrawLine(Pens.Black, new Point(20, 10 + 30), new Point(20 + with * 7, 10 + 30));
for (int i = 1; i <= 6; i++) //row
{
g.DrawLine(Pens.Black, new Point(20, 10 + 30 + height * i), new Point(20 + with * 7, 10 + 30 + height * i));
}
for (int i = 0; i < 8; i++) //column
{
g.DrawLine(Pens.Black, new Point(20 + with * i, 10), new Point(20 + with * i, 10 + 30 + height * 6));
}
for (int i = 0; i < 7; i++) //day
{
g.DrawString(day[i], head, new SolidBrush(Color.White), new PointF(20 + 20 + with * i, 15));
}
}
wuyq11 2010-12-30
  • 打赏
  • 举报
回复
贴出代码看看
whrspsoft3723 2010-12-30
  • 打赏
  • 举报
回复
顶你一下,哪里出现的?还是说清楚。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧