欢迎光临
我们一直在努力

快速对图片进行滤光处理-.NET教程,报表/图形/Office

建站超值云服务器,限时71元/月

想快速地对指定图片或区域进行滤光处理,常见的方法取出图片数据,逐像素与指定滤光色进行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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 快速对图片进行滤光处理-.NET教程,报表/图形/Office
分享到: 更多 (0)