回复 14楼 张live
可以在文本框中自定义分层数,颜色随机生成。
程序代码:
Option Explicit
Dim c() As Long
Private Sub Command1_Click()
Picture1.AutoSize = False
Picture2.AutoSize = False
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
End Sub
Private Sub Command2_Click()
GenColor
Dim i, j As Integer
Dim r, g, b As Integer
Dim color As Long
For i = 0 To Picture1.ScaleWidth
For j = 0 To Picture1.ScaleHeight
color = Picture1.Point(i, j)
r = (color And &HFF&)
Picture2.PSet (i, j), c(1 + Int(r / (256 / Val(Text1.Text))))
Next j
Next i
Picture2.Refresh
End Sub
Sub GenColor()
Dim i As Integer
For i = 1 To Val(Text1.Text)
ReDim Preserve c(i)
c(i) = RGB(Int(255 * Rnd + 1), Int(255 * Rnd + 1), Int(255 * Rnd + 1))
Next
End Sub