创建使用.NET手绘效果 [英] Creating a Hand-Drawn effect using .NET

查看:188
本文介绍了创建使用.NET手绘效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一张code创造图像风格类似那些渲染的 Balsamiq实体模型 yUML 使用' .NET框架。

I'd like to write a piece of code which creates images similar in style to those rendered by 'Balsamiq Mockups' or 'yUML' using the .NET framework.

谁能告诉我如何使用GDI实现手绘铅笔效果+?

Can anybody tell me how to achieve the hand-drawn pencil effect using GDI+?

文本显然可以使用合适的字体做 - 我的问题是如何呈现的线条,框和圆

The text can obviously be done using the right font - my question is how to render the lines, boxes and circles.

谢谢!

推荐答案

GDI +是最适合用于绘制直角型的图形,但是你可以用它来产生这样的效果:

GDI+ is best suited for drawing right-angle-type graphics, but you can use it to produce an effect like this:

...使用 DrawBezier 法的图形对象。下面是使上述图像code片断:

... by using the DrawBezier method of the Graphics object. Here's the code snippet that renders the above image:

Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
    g.FillRectangle(new SolidBrush(Color.White),
        new Rectangle(0, 0, bmp.Width, bmp.Height));
    Pen pen = new Pen(Color.Gray, 7.0F);
    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

    g.DrawBezier(pen,
        new Point(10, 10),
        new Point(11, 41),
        new Point(7, 147),
        new Point(13, 199));

    g.DrawBezier(pen,
        new Point(7, 10),
        new Point(87, 13),
        new Point(213, 17),
        new Point(319, 6));

    g.DrawBezier(pen,
        new Point(319, 4),
        new Point(305, 53),
        new Point(299, 107),
        new Point(319, 203));

    g.DrawBezier(pen,
        new Point(13, 199),
        new Point(33, 195),
        new Point(150, 207),
        new Point(319, 203));

}
pictureBox1.Image = bmp;

的关键在于这种效果是使用笔与大宽度(7.0F在这个例子中),并设置图形的Smoothi​​ngMode反对高质量的(因为这看起来像屁股的默认Smoothi​​ngMode)。

The keys to this effect are using a Pen with a large width (7.0F in this example), and setting the SmoothingMode of your Graphics object to HighQuality (since this looks like ass with the default SmoothingMode).

在这里指定的形状,在正常的GDI +的方式来绘制这将是比较容易编写自定义方法(矩形和坐标和半径等),然后你的code会将这些元素融入到贝塞尔的线坐标,你稍微随机几个像素在每个方向上改变事物的位置。

It would be relatively easy to write custom methods where you specify shapes to be drawn in the normal GDI+ way (rectangles and coordinates and radii and so forth), and then your code translates the lines of these elements into Bezier coordinates where you slightly alter the positions of things randomly by a few pixels in each direction.

这篇关于创建使用.NET手绘效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆