如何使多条线彼此渐变? [英] how do i make multiple lines gradient with each other?

查看:88
本文介绍了如何使多条线彼此渐变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在编写一种可以处理线条的绘画程序.
现在,当我尝试在自动色彩系统中植入一种渐变"时,
第一行的颜色为255; 0; 0,下一行的颜色为255; 1; 0,因此
继续...如果我将其设置为尝试从255; 0; 0转到
,则我一直陷入困境 255; 255; 255,它会升至255; 255; 0,并且不会再返回,如果返回
达到了.
这是我的代码.

就是这样,您知道picturebox2包含
的颜色 笔,而不是应该是渐变的一行.有很多不同的线
应该彼此渐变.

EDIT2(为了更清晰):如果我们说我们有color1和color2,并且color1 =
255; 0; 0和color2 = 255; 0; 255,然后对于每条线,我将其颜色绘制为
更像color2,因此第一行的颜色为255; 0; 0,下一行为
255; 0; 1第三个是255; 0; 2,依此类推

现在这是一些更新的代码..可以,但是它有很多错误,有时我会使用完全随机的颜色,它应该向上或向下:\

Edit4:此处使用 http://img227.imageshack.us/img227/337/testobject下面的代码进行一些测试. png

问题是,它有很多问题:(

Hello I''m writing a kind of a paint program that works with lines.
Now when I try in the auto color system to implant a kind of "gradient", so the
first line will get the color 255;0;0 and the next line will get 255;1;0 and so
on... I have been stuck at a problem, if I set it to try and go from 255;0;0 to
255;255;255, it goes to 255;255;0 and no further and it won''t go back if it
reached that.
Here''s my code for it.

Just so you know the picturebox2 contains the color for the
pen, and it''s not one line that should be gradient. It''s many different lines that
should be gradient with each other.

EDIT2 (for more clearance): if we say we have color1 and color2, and color1 =
255;0;0 and color2 = 255;0;255 then for every line i draw the color of the line be
more like color2 so that the first line has the color 255;0;0 the next line is
255;0;1 the third is 255;0;2 and so on

this is some updated code now.. this works but it''s quite buggy, sometimes i goes to a completely random color and it should just go up or down :\

here a little test with the code below http://img227.imageshack.us/img227/337/testobject.png

the problem is that it''s quite buggy :(

If cb5.Checked = True Then
                            Try
                                Dim c1 As Color = colo1.BackColor
                                Dim c2 As Color = colo2.BackColor
                                Dim pc1 As Color = PictureBox2.BackColor
                                If counter = 0 Then
                                    If pc1 = c2 Then
                                        counter = 1
                                    Else
                                        If pc1.R = c2.R Then
                                            If pc1.G = c2.G Then
                                                If pc1.B = c2.B Then
                                                    counter = 1
                                                Else
                                                    PictureBox2.BackColor = Color.FromArgb(pc1.R, pc1.G, pc1.B + 1)
                                                End If
                                            Else
                                                PictureBox2.BackColor = Color.FromArgb(pc1.R, pc1.G + 1, pc1.B)
                                            End If
                                        Else
                                            PictureBox2.BackColor = Color.FromArgb(pc1.R + 1, pc1.G, pc1.B)
                                        End If
                                    End If
                                ElseIf counter = 1 Then
                                    If pc1 = c1 Then
                                        counter = 0
                                    Else
                                        If pc1.B = c1.B Then
                                            If pc1.G = c1.G Then
                                                If pc1.R = c1.R Then
                                                    counter = 0
                                                Else
                                                    PictureBox2.BackColor = Color.FromArgb(pc1.R - 1, pc1.G, pc1.B)
                                                End If
                                            Else
                                                PictureBox2.BackColor = Color.FromArgb(pc1.R, pc1.G - 1, pc1.B)
                                            End If
                                        Else
                                            PictureBox2.BackColor = Color.FromArgb(pc1.R, pc1.G, pc1.B - 1)
                                        End If
                                    End If
                                End If
                            Catch
                            End Try
                            p = New Pen(PictureBox2.BackColor)
                            PictureBox1.Image = bit
                        End If



希望我已经很好地描述了它,并且我可以从您那里得到一些帮助. :)



I hope I have described it well and I can get some help from you. :)

推荐答案

笔可以使用渐变笔刷构建.我认为您想要的更像是这样:
Pens can be constructed with gradient brushes. I think what you want would be more like this:
Dim Rect As New Rectangle(0, 0, a, 1)

Using LGB As New LinearGradientBrush(Rect, Color1, Color2, LinearGradientMode.Horizontal)
    Using P As New Pen(LGB, 1)
        G.DrawLine(P, x, y, x + a, y + b)
    End Using
End Using


这将创建一个具有从Color1到Color2的水平渐变的画笔,使用它来构建厚度为1像素的笔,然后使用该笔绘制从(x,y)到(x + a,y + b)的线. Rect表示线条本身的边界,因此您需要根据线条是水平,垂直还是对角线来调整其大小.

其次,无需在控件中存储颜色.为什么不简单地使用几个Color对象?


This creates a brush having a horizontal gradient from Color1 to Color2, uses it to construct a pen with a thickness of 1 pixel, then uses the pen to draw a line from (x, y) to (x+a, y+b). Rect represents the boundaries of the line itself, so you will need to size it according to whether the line is horizontal, vertical or diagonal.

Second, there is no need to store colors in controls. Why not simply use a few Color objects?


为什么到底有人会编写包含任何图片框的绘画程序?在开始之前这是错误的. GDI +内置了渐变笔刷.
Why on earth would anyone write a paint program that contains any pictureboxes ? That''s just wrong before you start. GDI+ has gradient brushes built in.


这篇关于如何使多条线彼此渐变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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