也容易,如果是黑白三個顏色加上相同的漸變量,彩色的是起始顏色的三個分量與終止顏色的對應三個分量的差值,再除于相同的份數,就得出三原色各自的步進量。
成都創(chuàng)新互聯公司堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都網站設計、網站制作、外貿營銷網站建設、企業(yè)官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯網時代的藍山網站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!
窗體上放個圖片框試試下面代碼:
Private?Sub?PictureBox1_Paint(ByVal?sender?As?Object,?ByVal?e?As?System.Windows.Forms.PaintEventArgs)?Handles?PictureBox1.Paint
Dim?startColor?As?Color?=?Color.Red
Dim?endColor?As?Color?=?Color.Green
Dim?s?As?String?=?"vb.net?如何使文字能漸變顏色,就是顏色慢慢變淡然后在慢慢恢復?"
Dim?Steps?As?Integer?=?s.Length?\?2
Dim?StepR?As?Integer?=?(CInt(endColor.R)?-?startColor.R)?\?Steps
Dim?StepG?As?Integer?=?(CInt(endColor.G)?-?startColor.G)?\?Steps
Dim?StepB?As?Integer?=?(CInt(endColor.B)?-?startColor.B)?\?Steps
Dim?R?As?Integer?=?startColor.R
Dim?G?As?Integer?=?startColor.G
Dim?B?As?Integer?=?startColor.B
Dim?drawFont?As?New?System.Drawing.Font("Arial",?16)
Dim?X?As?Integer?=?50
For?i?As?Integer?=?1?To?Steps
Dim?drawBrush?As?New?SolidBrush(Color.FromArgb(R,?G,?B))
e.Graphics.DrawString(s.Substring(i?-?1,?1),?drawFont,?drawBrush,?X,?50.0)
X?+=?18
R?+=?StepR
G?+=?StepG
B?+=?StepB
Next
For?i?As?Integer?=?1?To?Steps
Dim?drawBrush?As?New?SolidBrush(Color.FromArgb(R,?G,?B))
e.Graphics.DrawString(s.Substring(i?+?Steps?-?1,?1),?drawFont,?drawBrush,?X,?50.0)
X?+=?18
R?-=?StepR
G?-=?StepG
B?-=?StepB
Next
End Sub
VB可使用Point方法來獲取圖片指定點的顏色。
Point 方法
按照長整數,返回在 Form 或 PictureBox 上所指定磅的紅-綠-藍 (RGB) 顏色。
語法
object.Point(x, y)
'窗體判色代碼:
Private Sub Form1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = X
Text2 = Y
Text3 = Point(X, Y)
Text4 = (Val(Text3) Mod 65536) Mod 256 'Red
Text5 = (Val(Text3) Mod 65536) \ 256 'Green
Text6 = Val(Text3) \ 65536 'Blue
Shape1.FillColor = RGB(Val(Text4), Val(Text5), Val(Text6))
End Sub
'PictureBox判色代碼:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1 = X
Text2 = Y
Text3 = Picture1.Point(X, Y)
Text4 = (Val(Text3) Mod 65536) Mod 256 'Red
Text5 = (Val(Text3) Mod 65536) \ 256 'Green
Text6 = Val(Text3) \ 65536 'Blue
Shape1.FillColor = RGB(Val(Text4), Val(Text5), Val(Text6))
End Sub
Label控件是沒有辦法實現多種顏色的文字的,只能用RichTextBox來實現,而且你的自定義格式字符串也沒有結尾的,這樣很不好,至少也要red紅色字/redyellow黃色字/yellow,而且實現也很麻煩的,下面的代碼我沒有檢測正確性,有錯誤的自己改一改吧
Dim colortag() as string
dim colors() as color
const txt as string="red紅色字/redyellow黃色字/yellow"
private sub Form_Load(object sender,eventargs e)handles mybase.load
colortag(0)="red":Colortag(1)="yellow"
colors(0)=color.red:colors(1)=color.yellow
richtextbox1.text=txt
for i as integer=0 to colortag.lenght-1
dim tag as string="" colortag(i) ""
dim endtag as string="/" colortag(i) ""
dim find as integer=1
do
find=instr(find,txt,tag)+tag.lenght
if(find0)then
dim find1 as integer=instr(find,txt,endtag)
richtextbox1.SelectionStart=find
richtextbox1.selectionlenght=find1-find
richtextbox1.selectioncolor=colors(i)
find=find1
else
exit do
end if
loop
next
end sub
繪制線條采用Draw開頭的方法,顏色參數用Pen類;
繪制有填充色的封閉圖形采用Fill開頭的方法,顏色參數用Brush類;
例如:
'繪制一個實心圓,該圓在:直線x=200,y=200,x=200+100,y=200+100所劃矩形區(qū)域內
Me.CreateGraphics.FillEllipse(New SolidBrush(Color.Orange), 200, 200, 100, 100)
'繪制一個空心圓,該圓在:直線x=200,y=200,x=200+100,y=200+100所劃矩形區(qū)域內
Me.CreateGraphics.DrawEllipse(New Pen(Color.Black), 200, 200, 100, 100)