Bitmap&Bitmap
-
Hi! I've the following problem: I've two bitmap variables, and I want to check that they contain the same image or not. If I try to use the "=" operator, I get an error message. I wrote a function what examines every pixel (by setpixel and getpixel methods), but it makes the program very slow. Isn't there a faster way? Thanks in advance.
-
Hi! I've the following problem: I've two bitmap variables, and I want to check that they contain the same image or not. If I try to use the "=" operator, I get an error message. I wrote a function what examines every pixel (by setpixel and getpixel methods), but it makes the program very slow. Isn't there a faster way? Thanks in advance.
Because VB sucks, no. But, if you did this in C# and called it from a dll, you could use direct pixel access, like I do in my image processing articles, which would be faster.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hi! I've the following problem: I've two bitmap variables, and I want to check that they contain the same image or not. If I try to use the "=" operator, I get an error message. I wrote a function what examines every pixel (by setpixel and getpixel methods), but it makes the program very slow. Isn't there a faster way? Thanks in advance.
Yes I had the same problem with get/setpixel. Here is what you do, create a file stream for each file then compare the file streams. If you need an example just let me know (don't worry it's real simple). I don't have the exact commands for it memorized but I have code for something similar on my laptop and I can give it to you later if you want me to.
-
Yes I had the same problem with get/setpixel. Here is what you do, create a file stream for each file then compare the file streams. If you need an example just let me know (don't worry it's real simple). I don't have the exact commands for it memorized but I have code for something similar on my laptop and I can give it to you later if you want me to.
I'll be very grateful if you send me the code. Much thanks
-
Because VB sucks, no. But, if you did this in C# and called it from a dll, you could use direct pixel access, like I do in my image processing articles, which would be faster.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Thanks
-
I'll be very grateful if you send me the code. Much thanks
A few notes. This will compare 2 files of ANY format not just bitmaps. path1 and path2 are your file paths. This will only work if the files are the same format(if you compare a 32 bit and 24 bit bitmap it will always return false). Also I have not tested this but I think it is correct but if you get an error or problem just let me know. I don't think there is much overhead with filestreams but if it isn't real fast then try using the read command at the bottom to read it into arrays then compare the arrays instead of the filestreams. If you need to compare different formats or if you are looking for a way to get or set pixels then I know how to do that but it is a little more involved than this since you have to match up pixels and so forth and it requires some knowledge of the bitmap format.
Public Function CompareFiles(ByVal path1 As String, ByVal path2 As String) As Boolean Dim n As Integer, issame As Boolean = True, fstream1 As IO.FileStream, fstream2 As IO.FileStream 'create streams fstream1 = New IO.FileStream(path1, IO.FileMode.Open, IO.FileAccess.Read) fstream2 = New IO.FileStream(path2, IO.FileMode.Open, IO.FileAccess.Read) 'compares the streams If fstream1.Length = fstream2.Length Then For n = 0 To fstream1.Length If fstream1.ReadByte <> fstream2.ReadByte Then issame = False Exit For End If Next Else issame = False End If fstream1.Close() fstream2.Close() Return issame End Function
The file stream is basically like an array of bytes. You can manipulate any file with file streams and if you want to copy data to or from an array use these commands.fstream1.Read(yourarray, youroffset, yourcount) fstream1.Write(yourarray, youroffset, yourcount)
-
A few notes. This will compare 2 files of ANY format not just bitmaps. path1 and path2 are your file paths. This will only work if the files are the same format(if you compare a 32 bit and 24 bit bitmap it will always return false). Also I have not tested this but I think it is correct but if you get an error or problem just let me know. I don't think there is much overhead with filestreams but if it isn't real fast then try using the read command at the bottom to read it into arrays then compare the arrays instead of the filestreams. If you need to compare different formats or if you are looking for a way to get or set pixels then I know how to do that but it is a little more involved than this since you have to match up pixels and so forth and it requires some knowledge of the bitmap format.
Public Function CompareFiles(ByVal path1 As String, ByVal path2 As String) As Boolean Dim n As Integer, issame As Boolean = True, fstream1 As IO.FileStream, fstream2 As IO.FileStream 'create streams fstream1 = New IO.FileStream(path1, IO.FileMode.Open, IO.FileAccess.Read) fstream2 = New IO.FileStream(path2, IO.FileMode.Open, IO.FileAccess.Read) 'compares the streams If fstream1.Length = fstream2.Length Then For n = 0 To fstream1.Length If fstream1.ReadByte <> fstream2.ReadByte Then issame = False Exit For End If Next Else issame = False End If fstream1.Close() fstream2.Close() Return issame End Function
The file stream is basically like an array of bytes. You can manipulate any file with file streams and if you want to copy data to or from an array use these commands.fstream1.Read(yourarray, youroffset, yourcount) fstream1.Write(yourarray, youroffset, yourcount)
Thanks :-D