[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1165
  • Last Modified:

Using the GetObjectA Function in VB.NET

In vb6, the syntax is Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long

The Problem:  In VB.NET, the ANY datatype is no longer used so I replace ANY with OBJECT as displayed below:

Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As OBJECT) As Long

and executed the function as:

 xint = GetObject(PictureBox1.Handle.ToInt32, Len(picinfo), picinfo)

xint returns a value indicating the functions was successful, however. picinfo is all 0's.

Can anyone help?
0
Vasguard
Asked:
Vasguard
  • 4
  • 2
1 Solution
 
Erick37Commented:
In .NET, 32 bit values are now Integers.  The correct declare would be:

Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Integer, ByVal nCount As Integer, ByRef lpObject As Object) As Integer
0
 
Erick37Commented:
BTW, the graphics handling capabilities in VB.NET are much more powerful than in VB6, so you may be able to accomplish what you are trying to do without using API calls.  What is it you need to do using GetObjectA?
0
 
VasguardAuthor Commented:
I am new to vb.net but where are some good sites to learn about the graphics.  All I am trying to do is compare two bitmaps and see if they are different or the same.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Erick37Commented:
When you say comparing bitmaps, do you mean testing to see that each pixel is identical to the corresponding pixel in the other bitmap?

0
 
VasguardAuthor Commented:
Yes, I want to detect in changes in the pixels.  Do you know how I could do that?
0
 
Erick37Commented:
Here is one way using the built-in GetPixel method of the Bitmap class:



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim pic1 As New Bitmap("c:\test.jpg")
        Dim pic2 As New Bitmap("c:\test.jpg")

        If ComparePicturesByGetPixel(pic1, pic2) = True Then
            MessageBox.Show("Bitmaps are the same")
        Else
            MessageBox.Show("Bitmaps are different")
        End If

    End Sub


    Private Function ComparePicturesByGetPixel(ByVal bm1 As Bitmap, ByVal bm2 As Bitmap) As Boolean
        If (bm1.Height <> bm2.Height) AndAlso (bm1.Width <> bm2.Height) Then
            'they are obviously not the same
            Return False
        Else
            'same dimensions, so compare pixels
            Dim h As Integer
            Dim w As Integer
            Dim px1 As Color
            Dim px2 As Color

            'compare each pixel in the bitmap
            For h = 0 To bm1.Height - 1
                For w = 0 To bm1.Width - 1
                    px1 = bm1.GetPixel(w, h)
                    px2 = bm2.GetPixel(w, h)
                    If Not px1.Equals(px2) Then
                        Return False
                    End If
                Next
            Next
        End If
        'if we got this far, they are equal
        Return True
    End Function
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now