Quickly filter the image

Source: Internet
Author: User
Tags filter

To quickly filter the specified picture or area, the common way to remove the image data, pixel and the specified filter color and operation, very troublesome. Also saw the online spread of useful point or getpixel operation, its low speed imaginable.

In fact, the use of BitBlt bit operations, can be done at a high speed, the following function than the array operation method can be 10 times times faster than point or getpixel estimates will be faster than thousand.

Private Type RECT
Left as Long
Top as Long
Right as Long
Bottom as Long
End Type
Private Declare Function deleteobject Lib "gdi32" (ByVal Hobject as long) as long
Private Declare Function createsolidbrush Lib "Gdi32.dll" (ByVal Crcolor as long) as long
Private Declare Function fillrect Lib "user32.dll" (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

Public Sub Filterrgb (dhdc as Long, X as long, y as Long, w as Long, h as long, Optional tc as Long = &hffff00)
Dim TMPHDC as MEMHDC, rc as RECT, hbrush as Long
TMPHDC = Newmyhdc (DHDC, W, h) ' Create a memory bitmap
Rc. right = W
Rc. Bottom = h
Hbrush = CreateSolidBrush (TC)
FillRect TMPHDC.HDC, RC, Hbrush ' fills the picture with the filter color, produces a solid color picture
DeleteObject Hbrush
BitBlt Dhdc, X, Y, W, H, tmphdc.hdc, 0, 0, Vbsrcand ' draw the target, and operation with the target, to achieve the filter effect
TMPHDC = DELMYHDC (TMPHDC)
End Sub

The common functions Newmyhdc, DELMYHDC, and associated structure and API declarations in this article can be found in the following articles
Http://blog.csdn.net/homezj/archive/2005/04/14/348001.aspx


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.