Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Bitmap&Bitmap

Bitmap&Bitmap

Scheduled Pinned Locked Moved Visual Basic
helpgraphicsquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    The real M
    wrote on last edited by
    #1

    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.

    C M 2 Replies Last reply
    0
    • T The real M

      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.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      T 1 Reply Last reply
      0
      • T The real M

        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.

        M Offline
        M Offline
        MikeMarq
        wrote on last edited by
        #3

        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.

        T 1 Reply Last reply
        0
        • M MikeMarq

          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.

          T Offline
          T Offline
          The real M
          wrote on last edited by
          #4

          I'll be very grateful if you send me the code. Much thanks

          M 1 Reply Last reply
          0
          • C Christian Graus

            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 )

            T Offline
            T Offline
            The real M
            wrote on last edited by
            #5

            Thanks

            1 Reply Last reply
            0
            • T The real M

              I'll be very grateful if you send me the code. Much thanks

              M Offline
              M Offline
              MikeMarq
              wrote on last edited by
              #6

              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)

              T 1 Reply Last reply
              0
              • M MikeMarq

                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)

                T Offline
                T Offline
                The real M
                wrote on last edited by
                #7

                Thanks :-D

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups