简体   繁体   English

c#draw - 在图像中添加随机线条

[英]c# draw - Add random lines in a image

I have an image which I just want to add some random lines in. I am not so familiar with c# draw features. 我有一个图像,我只想添加一些随机线。我不熟悉c#绘图功能。

Is there any simple way to add somewhere between 4-7 different length lines different places in an already bitmap object ? 有没有简单的方法在已经位图对象中的4-7个不同长度的行之间添加不同的位置?

Try something like this: 尝试这样的事情:

Random rnd = new Random();
Graphics g = Graphics.FromImage(bitmap);
for (int i=0; i<n; i++) {
    // calculate line start and end point here using the Random class:
    int x0 = rnd.Next(0, bitmap.Width);
    int y0 = rnd.Next(0, bitmap.Height);
    int x1 = rnd.Next(0, bitmap.Width);
    int y1 = rnd.Next(0, bitmap.Height);
    g.DrawLine(Pens.White, x0, y0, x1, x1);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM