时间: 2021-07-31 作者:daque
作家:任毅 photoshop图像处置软硬件最引人之处莫过于它的滤镜功效,即使你控制了少许vb的常识,那么你也不妨安排出图像处置巨匠级的滤镜功效。 开始你必需领会vb中图像处置的少许基础常识。在vb中有两个操纵像素的基础本领:pset和point。pset天生像素;point则读取像素值。而且表露器上所能表露的一切脸色都不妨用rgb值来表白,vb中供给了rgb()因变量,有三个变量rgb(red,green,blue),如rgb(255,0,0)表白赤色,rgb(255,255,0)表白黄色等。 vb中没有供给将一个像素点的脸色归来成rgb值的因变量,但咱们不妨用以次本领赢得某一点的rgb值: pi& = picture.point(x, y) red = pi& mod 256 green = ((pi& and &hff00) / 256&) mod 256& blue = (pi1& and &hff0000) / 65536 有了之上常识,再经过少许滤镜算法便不妨爆发少许很不错的滤镜功效。在此以浮雕、木版画、油画和道具共四个滤镜功效为例。 简直操纵办法如次: 兴建一个窗体 form1,在图体上创造一个picture1图像框,将其autosize的值设为 ture,而后用picture1的loadpicture()吩咐调入一幅图像,再经过百般事变挪用过滤进程(这边以picture1_click()事变来挪用)。 以次为简直代码: private sub form_load() form1.autoredraw = true form1.scalemode = 3 picture1.autoredraw = true picture1.scalemode = 3 picture1.picture = loadpicture(图像文献全道路名) end sub 浮雕 浮雕的算法是在相邻像素的差值上加上一个常数,使暗淡地区减少少许亮度,咱们不妨取同一条龙、同一列或对角线上的相邻像素间的差值加上一个常数。 private sub picture1_click() dim pi1&, pi2& dim x, y dim a, b as integer dim red, green, blue as integer a = 1 b = 1 xx = picture1.scalewidth yy = picture1.scaleheight for x = 1 to xx - 2 for y = 1 to yy - 2 pi1& = picture1.point(x, y) pi2& = picture1.point(x + a, y + b) red = abs((pi1& mod 256) - (pi2& mod 256) + 128) green = abs((((pi1& and &hff00) / 256&) mod 256&) - (((pi2& and &hff00) / 256&) mod 256&) + 128) blue = abs(((pi1& and &hff0000) / 65536) - ((pi2& and &hff0000) / 65536) + 128) picture1.pset (x, y), rgb(red, green, blue) next y next x picture1.refresh end sub 油画 油画滤镜的算法是:用暂时点边际确定范畴内任一点的脸色来包办暂时点的脸色。 private sub picture1_click() dim pi& dim x, y dim a, b as integer dim red, green, blue as integer xx = picture1.scalewidth yy = picture1.scaleheight for x = 2 to xx - 3 for y = 2 to yy - 3 a = rnd * 3 - 1 b = rnd * 3 - 1 pi = picture1.point(x + a, y + b) red = (pi& mod 256) green = (((pi& and &hff00) / 256&) mod 256&) blue = ((pi& and &hff0000) / 65536) picture1.pset (x, y), rgb(red, green, blue) next y doevents next x picture1.refresh end sub 木版画(图三) 这个滤镜的算法对立简简单点。只需确定暂时点是淡色仍旧深色(即三脸色元素的平衡值能否大于128),淡色用白色rgb(255,255,255)包办;深色用玄色rgb(0,0,0)包办。 private sub picture1_click() dim pi& dim x, y dim a, b as integer dim red, green, blue as integer a = 1 b = 1 xx = picture1.scalewidth yy = picture1.scaleheight for x = 0 to xx for y = 0 to yy pi = picture1.point(x, y) red = (pi& mod 256) green = (((pi& and &hff00) / 256&) mod 256&) blue = ((pi& and &hff0000) / 65536) if (red + green + blue) / 3 < 128 then picture1.pset (x, y), rgb(0, 0, 0) else picture1.pset (x, y), rgb(255, 255, 255) end if next y next x picture1.refresh end sub 道具 道具滤镜的算法很多,这边引见一种小口径道具滤镜,简直算法是取一点为光源(这边以30,40为例),从光彩终局发端向光源点渐渐减少亮度(向白色逼近)。代码为: private sub picture1_click() dim pi1&, pi2& dim x, y dim a, b as integer dim red, green, blue as integer a = 30 b = 40 xx = picture1.scalewidth yy = picture1.scaleheight for x = 1 to xx for y = 1 to yy pi1 = picture1.point(x, y) if sqr((a - x) * (a - x) + (b - y) * (b - y)) - 40 < 0 then red = ((pi1& mod 256) + 200 * (1 - (sqr((a - x) * (a - x) + (b - y) * (b - y)) + 1) / 40)) green = ((((pi1& and &hff00) / 256&) mod 256&) + 200 * (1 - (sqr((a - x) * (a - x) + (b - y) * (b - y)) + 1) / 40)) blue = (((pi1& and &hff0000) / 65536) + 200 * (1 - (sqr((a - x) * (a - x) + (b - y) * (b - y)) + 1) / 40)) if red < 0 then red = 0 if red > 255 then red = 255 if green < 0 then green = 0 if green > 255 then green = 255 if blue < 0 then blue = 0 if blue > 255 then blue = 255 picture1.pset (x, y), rgb(red, green, blue) end if next y next x picture1.refresh end sub