A)当我编写一个BMP文件然后将其读回到另一个位图对象时,这些对象看起来会有所不同。看起来水平和垂直分辨率都已更改。
B)当使位图对象的分辨率相同时,尽管所有属性都相同,但位图对象仍然显示为不同。
C)如果我将同一个BMP文件读入两个不同的位图对象两次,则这些对象看起来会有所不同。
最终,我想克隆较大位图的小部分,并依次与每个已知的先前生成的文件的内容进行比较,以确定我是否已有该小部分的文件。也就是说,通过将每个文件读取为位图,我希望能够与小节位图进行比较。
我最终将在每个文件的名称或属性中放置一个校验和,以便更快地排除,但仍将需要比较那些“幸免”的文件的每个内容,以防止具有相同校验和问题的不同文件。
运行时,以下代码显示了问题。
Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click
Dim sFileName As String = "c:\Temp\Red.bmp"
' Create red coloured bitmap
Dim oBitMap1 As New Bitmap(200, 100)
Dim oGraphics = Graphics.FromImage(oBitMap1)
oGraphics.FillRectangle(Brushes.Red, 0, 0, 200, 100)
Dim oBitMapA As New Bitmap(200, 100)
oBitMapA = oBitMap1
Debug.Print("oBitMap1 Is oBitMapA = " & CStr(oBitMap1 Is oBitMapA))
' Save the bitmap
oBitMap1.Save(sFileName, Imaging.ImageFormat.Bmp)
' Read the "same" details back into oBitMap2 & BitMap3
Dim oBitMap2 = New Bitmap(sFileName)
Dim oBitMap3 = New Bitmap(sFileName)
'Dim oBitMap2 As Bitmap = Image.FromFile(sFileName)
'Dim oBitMap3 As Bitmap = Image.FromFile(sFileName)
' Show what's what
Debug.Print("Show whether BitMaps are the same (pre changes)")
Debug.Print("oBitMap1 Is oBitMap2 = " & CStr(oBitMap1 Is oBitMap2))
Debug.Print("oBitMap2 Is oBitMap3 = " & CStr(oBitMap2 Is oBitMap3))
Debug.Print("Show resolutions (pre any changes)")
Debug.Print("oBitMap1.Resolution = " & Format(oBitMap1.HorizontalResolution, "##0.###") & "," & Format(oBitMap1.VerticalResolution, "##0.###"))
Debug.Print("oBitMap2.Resolution = " & Format(oBitMap2.HorizontalResolution, "##0.###") & "," & Format(oBitMap2.VerticalResolution, "##0.###"))
Debug.Print("oBitMap3.Resolution = " & Format(oBitMap3.HorizontalResolution, "##0.###") & "," & Format(oBitMap3.VerticalResolution, "##0.###"))
oBitMap2.SetResolution(96, 96)
oBitMap3.SetResolution(96, 96)
Debug.Print("Show resolutions (post changes)")
Debug.Print("oBitMap1.Resolution = " & Format(oBitMap1.HorizontalResolution, "##0.###") & "," & Format(oBitMap1.VerticalResolution, "##0.###"))
Debug.Print("oBitMap2.Resolution = " & Format(oBitMap2.HorizontalResolution, "##0.###") & "," & Format(oBitMap2.VerticalResolution, "##0.###"))
Debug.Print("oBitMap3.Resolution = " & Format(oBitMap3.HorizontalResolution, "##0.###") & "," & Format(oBitMap3.VerticalResolution, "##0.###"))
Debug.Print("Show whether BitMaps are the same (post changes)")
Debug.Print("oBitMap1 Is oBitMap1 = " & CStr(oBitMap1 Is oBitMap1))
Debug.Print("oBitMap1 Is oBitMap2 = " & CStr(oBitMap1 Is oBitMap2))
Debug.Print("oBitMap2 Is oBitMap3 = " & CStr(oBitMap2 Is oBitMap3))
End Sub
使用上面的描述
A)我期望从oBitMap1创建的文件中读取的oBitMap2与oBitMap1相同,但是分辨率不同。
B)当我将oBitMap2的分辨率设置为与oBitMap1相同时,我期望oBitMap1和oBitmap2相同,但是它们是不同的。
C)当我两次读取同一个文件时,我期望创建的两个位图(oBitMap2和oBitMap3)相同,但是它们是不同的。
我想知道我是否误解了“ Is”比较运算符,还是位图具有“隐藏”属性,当我在调试器中“打印”它们时,它们不显示,因为所有显示的属性似乎都是相同的。