注释: val()是把文本转为数字,str()是把数字转为文本
Public 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
打开图片
'目标图起点
'目标图起点
'目标图宽
'目标图高
'源图设备
'源图起点
'源图起点
'复制方式,如果完全复制,值为&HCC0020
CommonDialog1.Filter = \"(*.bmp)|*.bmp|(*.jpg)|*.jpg|(*.gif)|*.gif|(*.*)|*.*\"
CommonDialog1.ShowOpen
err:
打开图像数据
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
Picture2.Picture = Picture1.Picture
Picture3.Picture = Picture1.Picture
逆反处理
Label3.Caption = \"正在处理中...\"
width1 = Picture2.ScaleWidth
height1 = Picture2.ScaleHeight
Picture2 = Picture1
Picture2.Refresh
DoEvents
For i = 0 To width1 - 1
For j = 0 To height1 - 1
Col = Picture2.Point(i, j)
r1 = Col Mod 256
g1 = Col \\ 256 Mod 256
b1 = Col \\ 65536
If rr > 255 Then rr = 255: If rr < 0 Then rr = 0
If gg > 255 Then gg = 255: If gg < 0 Then gg = 0
If bb > 255 Then bb = 255: If bb < 0 Then bb = 0
rr = 255 - r1
gg = 255 - g1
bb = 255 - b1
Picture2.PSet (i, j), RGB(rr, gg, bb)
Next j
Next i
Label3.Caption = \"处理结果\"
平滑处理(3x3)
Label3.Caption = \"正在处理中...\"
width1 = Picture2.ScaleWidth
height1 = Picture2.ScaleHeight
Picture2 = Picture1
Picture2.Refresh
DoEvents
n = Val(Text1.Text): n1 = n * n: n2 = n \\ 2
For j = n2 To height1 - n2 - 1
For i = n2 To width1 - n2 - 1
rr = 0: gg = 0: bb = 0
For k1 = -n2 To n2
For k2 = -n2 To n2
p = Picture2.Point(i + k1, j + k2)
rr = rr + (p Mod 256)
gg = gg + (p \\ 256 Mod 256)
bb = bb + (p \\ 65536)
Next k2
Next k1
rr = rr / n1: gg = gg / n1: bb = bb / n1
Picture2.PSet (i, j), RGB(rr, gg, bb)
Next i
Next j
Label3.Caption = \"处理结果\"
霓虹处理
Label3.Caption = \"正在处理中...\"
width1 = Picture2.ScaleWidth
height1 = Picture2.ScaleHeight
Picture2 = Picture1
Picture2.Refresh
DoEvents
For j = 0 To height1 - 1
For i = 0 To width1 - 1
p1 = Picture2.Point(i, j)
p2 = Picture2.Point(i + 1, j)
p3 = Picture2.Point(i, j + 1)
rr = Sqr((p1 Mod 256 - p2 Mod 256) ^ 2 + (p1 Mod 256 - p3 Mod 256) ^ 2)
gg = Sqr((p1 \\ 256 Mod 256 - p2 \\ 256 Mod 256) ^ 2 + (p1 \\ 256 Mod 256 - p3 \\ 256 Mod 256) ^ 2)
bb = Sqr((p1 \\ 65536 - p2 \\ 65536) ^ 2 + (p1 \\ 65536 - p3 \\ 65536) ^ 2)
If rr > 255 Then rr = 255: If rr < 0 Then rr = 0
If gg > 255 Then gg = 255: If gg < 0 Then gg = 0
If bb > 255 Then bb = 255: If bb < 0 Then bb = 0
Picture2.PSet (i, j), RGB(rr, gg, bb)
Next i
Next j
Label3.Caption = \"处理结果\"
边缘锐化
Label3.Caption = \"正在处理中...\"
width1 = Picture2.ScaleWidth
height1 = Picture2.ScaleHeight
Picture2 = Picture1
Picture2.Refresh
DoEvents
For j = 1 To height1 - 1
For i = 1 To width1 - 1
p1 = Picture2.Point(i, j)
p2 = Picture2.Point(i - 1, j - 1)
rr = (p1 Mod 256 + Abs(p1 Mod 256 - p2 Mod 256)) / 2
gg = (p1 \\ 256 Mod 256 + Abs(p1 \\ 256 Mod 256 - p2 \\ 256 Mod 256)) / 2
bb = (p1 \\ 65536 + Abs(p1 \\ 65536 - p2 \\ 65536)) / 2
If rr > 255 Then rr = 255: If rr < 0 Then rr = 0
If gg > 255 Then gg = 255: If gg < 0 Then gg = 0
If bb > 255 Then bb = 255: If bb < 0 Then bb = 0
Picture2.PSet (i, j), RGB(rr, gg, bb)
Next i
Next j
Label3.Caption = \"处理结果\"
浮雕处理
Label3.Caption = \"正在处理中...\"
width1 = Picture2.ScaleWidth
height1 = Picture2.ScaleHeight
Picture2 = Picture1
Picture2.Refresh
DoEvents
For j = 0 To height1 - 1
For i = 1 To width1 - 1
p1 = Picture2.Point(i, j)
p2 = Picture2.Point(i +1, j)
rr = Abs(p1 Mod 256 - p2 Mod 256 + 128)
gg = Abs((p1 And &HFF00) / 256 Mod 256 - (p2 And &HFF00) / 256 Mod 256 + 128)
bb = Abs((p1 And &HFF0000) / 65536 - (p2 And &HFF0000) / 65536 + 128)
If rr > 255 Then rr = 255: If rr < 0 Then rr = 0
If gg > 255 Then gg = 255: If gg < 0 Then gg = 0
If bb > 255 Then bb = 255: If bb < 0 Then bb = 0
Picture2.PSet (i, j), RGB(rr, gg, bb)
Next i
Next j
Label3.Caption = \"处理结果\"
镶嵌处理(5x5)
Label3.Caption = \"正在处理中...\"
width1 = Picture2.ScaleWidth
height1 = Picture2.ScaleHeight
Picture2 = Picture1
Picture2.Refresh
DoEvents
For j = 0 To height1 -5 Step 5
For i = 0 To width1 - 5 Step 5
rr = 0: gg = 0: bb = 0
For k1 = 0 To 4
For k2 = 0 To 4
p = Picture2.Point(i + k1, j + k2)
rr = rr + p Mod 256: gg = gg + p \\ 256 Mod 256: bb = bb + p \\ 65536
Next k2
Next k1
rr = rr / 25: gg = gg / 25: bb = bb / 25
For k1 = 0 To 4
For k2 = 0 To 4
Picture2.PSet (i + k1, j + k2), RGB(rr, gg, bb)
Next k2
Next k1
Next i
Next j
Label3.Caption = \"处理结果\"
曝光处理
Label3.Caption = \"正在处理中...\"
width1 = Picture2.ScaleWidth
height1 = Picture2.ScaleHeight
Picture2 = Picture1
Picture2.Refresh
DoEvents
For j = 0 To height1 - 1
For i = 0 To width1 - 1
Col = Picture1.Point(i, j)
r1 = Col Mod 256
g1 = Col \\ 256 Mod 256
b1 = Col \\ 65536
If rr > 255 Then rr = 255: If rr < 0 Then rr = 0
If gg > 255 Then gg = 255: If gg < 0 Then gg = 0
If bb > 255 Then bb = 255: If bb < 0 Then bb = 0
If r1 < 128 Then r1 = 255 - r1
If g1 < 128 Then g1 = 255 - g1
If b1 < 128 Then b1 = 255 - b1
Picture2.PSet (i, j), RGB(r1, g1, b1)
Next i
Next j
Label3.Caption = \"处理结果\"
扩散处理(5x5)
Label3.Caption = \"正在处理中...\"
width1 = Picture2.ScaleWidth
height1 = Picture2.ScaleHeight
Picture2 = Picture1
Picture2.Refresh
DoEvents
n = Val(Text2.Text): n1 = n * n: n2 = n \\ 2
For j = n2 To height1 - n2 - 1
For i = n2 To width1 - n2 - 1
xx = Rnd() * (n - 1) - n2: yy = Rnd() * (n - 1) - n2
p = Picture2.Point(i + xx, j + yy)
r1 = p Mod 256
g1 = p \\ 256 Mod 256
b1 = p \\ 65536
Picture2.PSet (i, j), RGB(r1, g1, b1)
Next i
Next j
Label3.Caption = \"处理结果\"
油画效果
Label3.Caption = \"正在处理中...\"
width1 = Picture2.ScaleWidth
height1 = Picture2.ScaleHeight
Picture2 = Picture1
Picture2.Refresh
DoEvents
n = Val(Text1.Text): n1 = n * n: n2 = n \\ 2
For j = n2 To height1 - n2 - 1
For i = n2 To width1 - n2 - 1
k = Rnd() * n2 - 1
c = Picture2.Point(i + k, j + k)
rr = c Mod 256
gg = (c And &HFF00) / 256 Mod 256
bb = (c And &HFF0000) / 65536
If rr > 255 Then rr = 255: If rr < 0 Then rr = 0
If gg > 255 Then gg = 255: If gg < 0 Then gg = 0
If bb > 255 Then bb = 255: If bb < 0 Then bb = 0
Picture2.PSet (i, j), RGB(rr, gg, bb)
Next i
Next j
Label3.Caption = \"处理结果\"
旋转90°C(缺少函数定义)
Label3.Caption = \"正在处理中...\"
width1 = Picture2.ScaleWidth
height1 = Picture2.ScaleHeight
Picture2 = Picture1
Picture2.Refresh
DoEvents
For i = 0 To width1 Step 1
For j = 0 To height1 Step 1
Bitblt Picture2.hDC, h - j - 1, i, 1, 1, Picture1.hDC, i, j, &HCC0020
Next j
Next i
Label3.Caption = \"处理结果\"