图像比较问题
最近在写一个程序,涉及到图片比较问题,希望大家能帮忙解决一下。有两张图片a,b b大部分和a一样,只有一小点不一样,想让程序把b中和a不一样的部分用其他颜色表示出来,在picture中显示
网上说是要比较两张图片的RGB ,可是我实在不知道是哪个函数,有高手还希望指教一下,给个例子也行,先谢过了· --------------------编程问答-------------------- 关注…… --------------------编程问答-------------------- getpixel取像双循环取像素RGB颜色值进行比较,这样可行吗?这样可能效率会很低。 --------------------编程问答-------------------- 已解决,把源码发过来给关注的人
Private Sub find_difference()
Dim xlen As Long
Dim hdc As Long
Dim x As Long, y As Long
Dim lcolor As Long, Rcolor As Long, Scolor As Long
xlen = X2 - X1
hdc = GetDC(0)
Scolor = SelectColor()
For y = Y1 To (Y1 + L)
For x = X1 To (X1 + K)
lcolor = GetPixel(hdc, x, y)
Rcolor = GetPixel(hdc, x + xlen, y)
If IsSame(lcolor, Rcolor) = True Then
t = SetPixel(Picture3.hdc, (x - X1) / 3, (y - Y1) / 3, Rcolor)
Else
t = SetPixel(Picture3.hdc, (x - X1) / 3, (y - Y1) / 3, Scolor)
End If
Next x
Next y
End Sub
实现了扫描屏幕上的两幅图片,做比较(issame)后,把差异用其他颜色(selectcolor)输出
程序效果还可以,就是效率问题有待解决,希望有高手指点 --------------------编程问答--------------------
Option Explicit
'大家来找茬
Private Sub Command1_Click()
Picture1.PaintPicture Picture2.Image, 0, 0, , , , , , , vbSrcInvert
End Sub
Private Sub Form_Load()
Picture1.AutoRedraw = True
Picture1.ScaleMode = vbPixels
Picture1.Line (0, 0)-(100, 100)
Picture2.AutoRedraw = True
Picture2.ScaleMode = vbPixels
Picture2.Line (0, 0)-(100, 100)
Picture2.Circle (50, 50), 10
End Sub
补充:VB , 多媒体