-
vb教程之透明方式叠加图象
透明叠加方式是图象处理中常用的一种处理方式,在这种处理方式中,一幅图片叠加到另
一幅图片上,但是这幅图象不是完全将原来的图象覆盖,而是能够部分的透过叠加的图象显示
出来,下面我就介绍如何在VB中编程实现这样的功能。
首先在建立两个大小相等的图象文件,将它们保存成BMP文件,VB5以上的版本支
持JPEG显示,也可以保存为Jpg文件。在Form中加入两个PictureBox控件,将它们的大小设置成
同图象文件相同的大小。注意这两个PictureBox控件不要相互重叠,也不要和Form中的其它控件
产生重叠。将两幅图象分别加入到两个PictureBox控件中。然后在Form中加入一个CommandButton
控件。最后在Form的代码窗口中加入以下代码:
Private Type LOGBRUSH
lbStyle As Long
lbColor As Long
lbHatch As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal _
hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) _
As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc _
As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
ByVal hObject As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, _
lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc _
As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush _
As LOGBRUSH) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Const SRCPAINT = &HEE0086
Const SRCAND = &H8800C6
Const BS_SOLID = 0
Const gColor = &HFFFFFF
Private Sub Command1_Click()
Dim pDstDC As Long
Dim dcCompatible As Long
Dim pBitmapOld As Long
Dim bm As Long
Dim rectTemp As RECT
Dim lBrush As Long
Dim tLog As LOGBRUSH
dcCompatible = CreateCompatibleDC(Picture1.hdc)
bm = CreateCompatibleBitmap(Picture1.hdc, Picture1.Width \ 15, _
Picture1.Height \ 15)
pBitmapOld = SelectObject(dcCompatible, bm)
rectTemp.Left = 0: rectTemp.Top = 0
rectTemp.Right = Picture1.Width \ 15: rectTemp.Bottom = _
Picture1.Height \ 15
tLog.lbColor = gColor
tLog.lbStyle = BS_SOLID
tLog.lbHatch = 0
lBrush = CreateBrushIndirect(tLog)
FillRect dcCompatible, rectTemp, lBrush
BitBlt Picture1.hdc, 0, 0, Picture1.Width \ 15, _
Picture1.Height \ 15, dcCompatible, 0, 0, SRCAND
SelectObject dcCompatible, pBitmapOld
BitBlt Picture1.hdc, 0, 0, Picture1.Width \ 15, _
Picture1.Height \ 15, Picture2.hdc, 0, 0, SRCPAINT
DeleteDC dcCompatible
End Sub
运行程序,点击Command1,你就可以看到Picture2上的图象叠加到了Picture1上面了。改变上面
源程序中的 Const gColor = &HFFFFFF 一句中的gColor的值(在0到&HFFFFFFFF间变动),就可以
使图象的叠加产生不同的透明效果。
以上程序在Win98、VB6.0下运行通过。
一幅图片上,但是这幅图象不是完全将原来的图象覆盖,而是能够部分的透过叠加的图象显示
出来,下面我就介绍如何在VB中编程实现这样的功能。
首先在建立两个大小相等的图象文件,将它们保存成BMP文件,VB5以上的版本支
持JPEG显示,也可以保存为Jpg文件。在Form中加入两个PictureBox控件,将它们的大小设置成
同图象文件相同的大小。注意这两个PictureBox控件不要相互重叠,也不要和Form中的其它控件
产生重叠。将两幅图象分别加入到两个PictureBox控件中。然后在Form中加入一个CommandButton
控件。最后在Form的代码窗口中加入以下代码:
Private Type LOGBRUSH
lbStyle As Long
lbColor As Long
lbHatch As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal _
hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) _
As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc _
As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
ByVal hObject As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, _
lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc _
As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateBrushIndirect Lib "gdi32" (lpLogBrush _
As LOGBRUSH) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Const SRCPAINT = &HEE0086
Const SRCAND = &H8800C6
Const BS_SOLID = 0
Const gColor = &HFFFFFF
Private Sub Command1_Click()
Dim pDstDC As Long
Dim dcCompatible As Long
Dim pBitmapOld As Long
Dim bm As Long
Dim rectTemp As RECT
Dim lBrush As Long
Dim tLog As LOGBRUSH
dcCompatible = CreateCompatibleDC(Picture1.hdc)
bm = CreateCompatibleBitmap(Picture1.hdc, Picture1.Width \ 15, _
Picture1.Height \ 15)
pBitmapOld = SelectObject(dcCompatible, bm)
rectTemp.Left = 0: rectTemp.Top = 0
rectTemp.Right = Picture1.Width \ 15: rectTemp.Bottom = _
Picture1.Height \ 15
tLog.lbColor = gColor
tLog.lbStyle = BS_SOLID
tLog.lbHatch = 0
lBrush = CreateBrushIndirect(tLog)
FillRect dcCompatible, rectTemp, lBrush
BitBlt Picture1.hdc, 0, 0, Picture1.Width \ 15, _
Picture1.Height \ 15, dcCompatible, 0, 0, SRCAND
SelectObject dcCompatible, pBitmapOld
BitBlt Picture1.hdc, 0, 0, Picture1.Width \ 15, _
Picture1.Height \ 15, Picture2.hdc, 0, 0, SRCPAINT
DeleteDC dcCompatible
End Sub
运行程序,点击Command1,你就可以看到Picture2上的图象叠加到了Picture1上面了。改变上面
源程序中的 Const gColor = &HFFFFFF 一句中的gColor的值(在0到&HFFFFFFFF间变动),就可以
使图象的叠加产生不同的透明效果。
以上程序在Win98、VB6.0下运行通过。
最新更新
python爬虫及其可视化
使用python爬取豆瓣电影短评评论内容
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比