快速對圖片進行濾光處理

來源:互聯網
上載者:User

想快速地對指定圖片或地區進行濾光處理,常見的方法取出圖片資料,逐像素與指定濾光色進行AND運算,很麻煩。還見過網上流傳的有用Point或GetPixel取點運算的,其低速可想而知。

其實利用BitBlt的位元運算,可高速完成這種操作,下面這個函數比數組運算方法可快10倍,比Point或GetPixel估計會快上千倍。

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)   '建立一個記憶體位元影像
    rc.Right = w
    rc.Bottom = h
    hBrush = CreateSolidBrush(tc)
    FillRect tmphdc.hdc, rc, hBrush '用濾光色填充圖片,產生一個純色圖片
    DeleteObject hBrush
    BitBlt dHdc, X, y, w, h, tmphdc.hdc, 0, 0, vbSrcAnd   '繪入目標,並與目標進行And運算,達到濾光效果
    tmphdc = DelMyHdc(tmphdc)
End Sub

本篇中的公用函數NewMyHdc、DelMyHdc及相關結構與API聲明,可在以下文章中找到
http://blog.csdn.net/homezj/archive/2005/04/14/348001.aspx


相關文章

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。