(vb)利用GetBitmapBits,SetBitmapBits加速图像处理

本文介绍了如何利用VB中的GetBitmapBits和SetBitmapBits函数来加速图像处理,特别是图像旋转操作。通过直接操作位图的二进制数据,实现了比使用SetPixelV和GetPixel更快的图像旋转功能。作者提供了顺时针旋转90度的函数示例,展示了在不同环境下运行的速度提升。
摘要由CSDN通过智能技术生成

(vb)利用GetBitmapBits,SetBitmapBits加速图像处理

(不知道前面有没有人写过这个,这里主要是最近写程序的一些心得,希望对大家有用.久未写东西,会有一堆的毛病,将就着吧.)

最近发现了两个好东东,SetBitmapBits,GetBitmapBits,能极大的提高某些图像处理的速度.

引用别人的话
"SetBitmapBits:
 vb声明: Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
 作用: "将来自缓冲区的二进制位复制到一幅位图"
 参数: hBitmap Long,位图的句柄
  dwCount Long,欲复制的字节数量
  lpBits Any,指向一个缓冲区的指针。这个缓冲区包含了为位图正确格式化的位图位


GetBitmapBits:
 vb声明: Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
        作用: "将来自位图的二进制位复制到一个缓冲区"
 参数: hBitmap Long,位图的句柄
  dwCount Long,欲复制的字节数。如设为零,表示取得位图中的字节数
  lpBits Any,指向容纳位图位的一个缓冲区的指针。注意事先将缓冲区至少初始化成dwCount个字节 "


举一个例子,将图片旋转90度,下面是我写的顺时针旋转90度的函数.
假设目标图像的宽等于源图的长,目标图像的长等于源图的宽,两图颜色值占用的位数相等.
参数:

Using DIB Sections in VB An Easy to Use Class for manipulating DIBSections plus a blindingly quick technique for updating the bits Updated! 17 February 1999 The previous version of this code crashed when run under NT4.0. This was because the code was not always clearing up the SAFEARRAY pointer after it had finished using it. Under Win9x, this did not cause a problem but NT is stricter. All the samples and the code are now updated to fix this problem. This is a supporting article describing in more detail the DIB Section techniques used in the vbAccelerator Image Processor. It describes what DIB Sections are, how to use them and provides a class I wrote to wrap up the DIB Section. What is a DIB Section?A DIB (Device Independent Bitmap) Section is a GDI object like a standard DIB but which additionally provides a pointer to the memory used to store the bitmap bits to which the creating application has direct access. This allows ultimate flexibility if you want to modify the bits of a bitmap. Using DIB SectionsA DIB section is created using the GDI CreateDIBSection call. You need to modify the declare provided for this in the VB API guide because this declare assumes you cannot use the pointer to the bitmap returned by the function and simply discards it. Here are the declares you need:Private Type BITMAPINFOHEADER '40 bytes biSize As Long biWidth As Long biHeight As Long biPlanes As Integer biBitCount As Integer biCompression As Long biSizeImage As Long biXPelsPerMeter As Long biYPelsPerMeter As Long biClrUsed As Long biClrImportant As Long End Type Private Type BITMAPINFO bmiHeader As BITMAPINFOHEADER bmiColors As RGBQUAD End Type ' Note - this is not the declare in the API viewer - modify lplpVoid to be ' Byref so we get the pointer back: <b
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值