VB中生成位图

来源:百度知道 编辑:UC知道 时间:2024/06/18 05:32:43
VB中如何生成一指定颜色值(RGB值)的位图?
比如
1.单击按钮command1时 在picturebox1控件中生成一颜色值R=10 B=20 C=30 的位图
2.单击按钮command2时 在指定文件夹“D:\VB\bmp\”中生成一位图文件a.bmp 位图颜色值为R=10 B=20 C=30
以上生成的位图均为单一颜色的色块 还要指定位图的尺寸

Private Sub Form_Load()
Me.ScaleMode = 3
Picture1.BorderStyle = 0
Picture1.ScaleMode = 3
Picture1.AutoSize = True

End Sub

Private Sub Command1_Click()
Dim iWidth As Integer
Dim iHeight As Integer

iWidth = 100'位图宽度
iHeight = 100'位图高度

Picture1.Picture = LoadPicture("")
Picture1.BackColor = RGB(10, 20, 30)
Picture1.Width = iWidth
Picture1.Height = iHeight
Picture1.Cls

End Sub

Private Sub Command2_Click()
SavePicture Picture1.Image, "d:\vb\bmp\a.bmp"

End Sub

Private Sub Command1_Click()
Dim R As Integer, G As Integer, B As Integer
Dim KD As Long, GD As Long

KD = 2000: GD = 3000 '宽度,高度

Picture1.Width = KD
Picture1.Height = GD
Picture1.Cls
Randomize

'颜色的RGB值
R = Int(Rnd * 255 + 1)
G = Int(Rnd * 255 + 1)