文章目录
现在很多工业设计还在使用vb开发,稍微懂点历史的人,都知道VB语法比C类先进太多,vb写出的程序体积很小,那些重量级语言写出的程序没写代码都要占上百KB,用VB写到上百KB的程序已经是功能相当齐全的了。
vb编写小工具首选,分分钟就能出炉使用,不像net写个小程序,配置和编译花的精力都比写代码多,所以简单实现一下BMP图像文件的读取、显示与存储。
一、新建工程
1、新建一个exe文件

2、保存文件

3、在窗体上建立图片框

4、加入控制按钮

二、编程实现
1、双击窗体,加入程序
工程1窗体的编程界面,将一下写入
Private Sub Command1_Click()
Picture1.AutoSize = True 'ÉèÖÃPictureµÄ´óС¿ÉÒÔËæ¶ÁÈëͼƬ½øÐб仯£¬Ê¹ÆäÓëͼƬµÄ´óСÏà·û
Picture2.AutoRedraw = True 'ÉèÖÃPicture2¿É½øÐÐÖØ»
Command1.Caption = "打开图像"
Command2.Caption = "保存图像"
Command3.Caption = "图像灰度化"
Command4.Caption = "保存灰度图像"
Command5.Caption = "退出"
End Sub

2、点击运行按钮,观察效果

3、对Command1(打开图像)图像进行编程
Private Sub Command1_Click()
Picture1.Picture = LoadPicture("D:\pic\HG.bmp") '打开并显示图片
Picture2.Width = Picture1.Width '设置picture2的宽度与picture1的相同
Picture2.Height = Picture1.Height '设置picture2的高度与picture1的相同
End Sub

4、点击“打开图像”显示效果

5、对Command2(保存图像)图像进行编程
Private Sub Command2_Click()
SavePicture Picture1.Picture, "D:\pic\new.bmp"
End Sub

6、对Command3(图像灰度化)图像进行编程
Private Sub Command3_Click()
For i = 0 To Picture1.Width - 1
For j = 0 To Picture1.Height - 1
c = Picture1.Point(i, j)
R = c And &HFF&
G = (c And &HFF00&) / 256
B = (c And &HFF0000) / 65535
y = (R + G + B) / 3
Picture2.PSet (i, j), RGB(y, y, y)
Next j
Next i
End Sub

7、对Command4(保存图像)进行编程
Private Sub Command4_Click()
SavePicture Picture1.Picture, "D:\pic\gray.bmp"
End Sub

8、对Command5(退出)进行编程
Private Sub Command5_Click()
End
End Sub

三、成果展示
实现BMP图像文件的读取、显示与存储

2778

被折叠的 条评论
为什么被折叠?



