如何比较两个.jpg文件或.gif文件是不是一样?

imur 2003-09-12 02:37:07
如何比较两个.jpg文件或.gif文件是不是一样?
比如a.jpg就是一个“1”的图片,而b.jpg就是“2”的图片,c.jpg是一个“1”的图片。
请问:如何比较a.jpg不同于b.jpg,而和c.jpg相同?
对于其它的格式,如.gif等呢?

请教请教!
...全文
113 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
boydgmx 2003-11-07
  • 打赏
  • 举报
回复
只能判定相似,不能判定全等,除非这两个图片是完全复制的。
imur 2003-11-05
  • 打赏
  • 举报
回复
继续请教!
lsm0959 2003-10-30
  • 打赏
  • 举报
回复
好复杂

msgbox "请自行用internet exploer打开比较"
jordi2014 2003-10-30
  • 打赏
  • 举报
回复
up
imur 2003-09-16
  • 打赏
  • 举报
回复
To 5653325(等待开刃的刀) 大侠:
我不会写啊,能不能帮帮?
谢谢了!
道素 2003-09-15
  • 打赏
  • 举报
回复
这是用象素比较的方法
Option Explicit

Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long
Private Declare Function SetBitmapBits Lib "gdi32" (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long



Private Sub Command1_Click()

Picture1.AutoSize = True
Picture2.AutoSize = True
Picture1.Picture = LoadPicture("C:\temp\test.bmp")
Picture2.Picture = LoadPicture("C:\temp\test.bmp")
' Picture2.Picture = LoadPicture("C:\Temp\test2.bmp")
MsgBox fComparePic(Picture1, Picture2)



End Sub


Public Function fComparePic(pic As PictureBox, pic2 As PictureBox) As Boolean

Dim PicBits() As Byte, PicInfo As BITMAP
Dim PicBits2() As Byte, PicInfo2 As BITMAP
Dim i As Long, BytesPerLine As Long


GetObject pic.Image, Len(PicInfo), PicInfo
GetObject pic2.Image, Len(PicInfo2), PicInfo2

If PicInfo.bmWidth <> PicInfo2.bmWidth Then
fComparePic = False
Exit Function
End If

If PicInfo.bmHeight <> PicInfo2.bmHeight Then
fComparePic = False
Exit Function
End If

'reallocate storage space
BytesPerLine = (PicInfo.bmWidth * 3 + 3) And &HFFFFFFFC
ReDim PicBits(1 To BytesPerLine * PicInfo.bmHeight * 3) As Byte

BytesPerLine = (PicInfo2.bmWidth * 3 + 3) And &HFFFFFFFC
ReDim PicBits2(1 To BytesPerLine * PicInfo2.bmHeight * 3) As Byte

GetBitmapBits pic.Image, UBound(PicBits), PicBits(1)
GetBitmapBits pic2.Image, UBound(PicBits2), PicBits2(1)


For i = 1 To UBound(PicBits)
If PicBits(i) <> PicBits2(i) Then
fComparePic = False
Exit Function
End If
Next i

fComparePic = True

End Function


=============================
我歌月徘徊,我舞影零乱。醒时同交欢,醉后各分散。 永结无情游,相期邈云
汉。
踏平扶桑 2003-09-15
  • 打赏
  • 举报
回复
用二进制比较如何?
imur 2003-09-15
  • 打赏
  • 举报
回复
谢谢ch21st(风尘鸟)大侠!
如果直接比较,代码如何写呢?我是菜鸟,sorry
请教!
道素 2003-09-15
  • 打赏
  • 举报
回复
加载到picturebox有一个作用,就是已经被转化为bitmap图像了
如果直接用文件比较,你干脆采用和比较其他二进制文件一样按二进制值比较就省去还有分析文件格式那么罗索
imur 2003-09-15
  • 打赏
  • 举报
回复
谢谢楼上大侠!
请教:能不能不要引入Picturebox控件,只是知道文件名称如:c:\a.jpg,c:\b.jpg,c:\c.jpg,这样就可以比较文件是不是相同了?
谢谢先!

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧