PictureBox2.ImageLocation = "en.gif"

cablehead

Member
Joined
Sep 13, 2005
Messages
10
Programming Experience
3-5
VB.NET:
Public [/color][/size][size=2][color=#0000ff]Shared [/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] ImagesAreTheSame([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] bmp1 _
 
[/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] bmp2 [/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap) [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Boolean

How can I send the Picture2.Image to the above function (as bitmap)?

Thanks


Full Function:

VB.NET:
[size=2][color=#0000ff][size=2][color=#0000ff]Public [/color][/size][size=2][color=#0000ff]Shared [/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2][color=#000000] ImagesAreTheSame([/color][/size][size=2][color=#0000ff]ByVal[/color][/size][size=2][color=#000000] bmp1 _[/color]
 
[/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] bmp2 [/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap) [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Boolean
 
[/color][/size][size=2][color=#008000]'If the images aren't the same size, quit 
 
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] bmp1.Size.Width <> bmp2.Size.Width [/size][size=2][color=#0000ff]OrElse[/color][/size][size=2] _
 
bmp1.Size.Height <> bmp2.Size.Height [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2][color=#0000ff]Return [/color][/size][size=2][color=#0000ff]False
 
[/color][/size][size=2][color=#0000ff]Else
 
[/color][/size][size=2][color=#008000]'Convert each image to a byte array
 
[/color][/size][size=2][color=#008000]'.NET.NET()
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] ic [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Drawing.ImageConverter = _
 
[/size][size=2][color=#0000ff]New[/color][/size][size=2] System.Drawing.ImageConverter
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] btImage1() [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Byte[/color][/size][size=2] = [/size][size=2][color=#0000ff]New [/color][/size][size=2][color=#0000ff]Byte[/color][/size][size=2](1) {}
 
btImage1 = [/size][size=2][color=#0000ff]CType[/color][/size][size=2](ic.ConvertTo(bmp1, _
 
btImage1.GetType()), [/size][size=2][color=#0000ff]Byte[/color][/size][size=2]())
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] btImage2() [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Byte[/color][/size][size=2] = [/size][size=2][color=#0000ff]New [/color][/size][size=2][color=#0000ff]Byte[/color][/size][size=2](1) {}
 
btImage2 = [/size][size=2][color=#0000ff]CType[/color][/size][size=2](ic.ConvertTo(bmp2, _
 
btImage2.GetType()), [/size][size=2][color=#0000ff]Byte[/color][/size][size=2]())
 
[/size][size=2][color=#008000]'The byte arrays may be different lengths if they 
 
[/color][/size][size=2][color=#008000]'contain different metadata, e.g. EXIF, TIFF tags 
 
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] btImage1.Length <> btImage2.Length _
 
[/size][size=2][color=#0000ff]Then [/color][/size][size=2][color=#0000ff]Return [/color][/size][size=2][color=#0000ff]False
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] i [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer
 
[/color][/size][size=2][color=#0000ff]For[/color][/size][size=2] i = 0 [/size][size=2][color=#0000ff]To[/color][/size][size=2] btImage1.Length - 1
 
[/size][size=2][color=#0000ff]If[/color][/size][size=2] btImage1(i) <> btImage2(i) [/size][size=2][color=#0000ff]Then [/color][/size][size=2][color=#0000ff]Return [/color][/size][size=2][color=#0000ff]False
 
[/color][/size][size=2][color=#0000ff]Next
 
[/color][/size][size=2][color=#0000ff]Return[/color][/size][size=2][color=#0000ff]True
 
[/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]If
 
[/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Function
[/color][/size][/color][/size]
 
Last edited by a moderator:
Hi,
Are you trying to only check if Picture1.Image is matching dimensions of Picture2.Image?
If it's so, i beleive you only need to declare new bitmap and pass a pictureBox.image in

OK, how about this?
VB.NET:
[size=2][color=#0000ff]Dim[/color][/size][size=2] myBMP1 [/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap[/size]
[size=2][color=blue]Dim[/color][size=2] myBMP2 [/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap[/size]
myBMP1 = PictureBox1.Image
myBMP2 = PictureBox2.Image
then:
VB.NET:
ImagesAreTheSame(myBMP1, myBMP2)


HTH
Regards ;)
[/size]
 
Not just width and height....if its an exact copy...


yes the compiler is asking for a "New" keyword in the function.

i just cant figure who what or where.
 
Ok, let's cut off this confusing thread. What is your idea about these bitmaps? EXPLAIN IN BRIEF and I'll make you another code ... function, sub whatever.


Otherwise, if you still want to keep up existing code you can get the pic like this (i assume you want to load pictures from your HD):

VB.NET:
Dim[/color][/size][size=2] myBMP1 [/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap
 
myBMP1 = [/size][size=2][color=#0000ff]New[/color][/size][size=2] Bitmap("C:\myPic1.bmp")
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] myBMP2 [/size][size=2][color=#0000ff]As[/color][/size][size=2] Bitmap
 
myBMP2 = [/size][size=2][color=#0000ff]New[/color][/size][size=2] Bitmap("C:\myPic2.bmp")[/size]
[size=2]
 
Last edited:
lol. this does it:

PictureBox1.ImageLocation = Application.StartupPath & "\en.gif"

Dim bm As New Bitmap(PictureBox1.InitialImage)

Dim bm2 As New Bitmap(Application.StartupPath & "\tile.gif")

Dim c As Boolean

c = ImagesAreTheSame(bm, bm2)

MsgBox(c)

 
Back
Top