Ok so I made a class (.cls file) for handling graphics. Here's the declarations in my class.
Code:Private Declare Function GetDIBits Lib "GDI32.dll" ( _ ByVal hDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, _ ByVal nNumScans As Long, ByRef lpBits As Any, _ ByRef lpBI As BitmapInfo, ByVal wUsage As Long) As Long Private Declare Function SetDIBits Lib "GDI32.dll" ( _ ByVal hDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, _ ByVal nNumScans As Long, ByRef lpBits As Any, _ ByRef lpBI As BitmapInfo, ByVal wUsage As Long) As Long Private Type BitmapInfoHeader biSize As Long biWidth As Long biHeight As Long biPlanes As Integer biBitCount As Integer biCompression As Long biSizeImage As Long biXPelsPerMeter As Long biYPelsPerMeter As Long biClrUsed As Long biClrImportant As Long End Type Private Type BitmapInfo bmiHeader As BitmapInfoHeader bmiColors(255) As Long End Type Dim DIBinfo As BitmapInfo Dim MyPic As PictureBox
Here's the functions in the class that are having a problem
Code:Public Property Set PictBox(ByRef PicBox As PictureBox) Set MyPic = PicBox End Property Public Sub GetPixels() DIBinfo.bmiHeader.biSize = Len(DIBinfo.bmiHeader) GetDIBits MyPic.hDC, MyPic.Image, 0, 0, ByVal 0&, DIBinfo, 0 MsgBox Dibinfo.bmiHeader.biWidth MsgBox Dibinfo.bmiHeader.biHeight End Sub
Now the initial size of my Picture1 picture box is 256x224.
Now the code I'm using in my form in the command button's "click" event, to test my API functions is
What is going on? Please help. Am I just overlooking something very obvious and easy to correct here?Code:Dim BM As New Bitmap 'Bitmap is the name of my class Set BM.PictBox = Picture1 BM.GetPixels 'The first MsgBox shows "256" and the second one shows "224" Picture1.Height=80 Set BM.PictBox = Picture1 BM.GetPixels 'As expected, the GDI API correctly reads the new smaller size of Picture1 and the first MsgBox shows "256" and the second one shows "80" Picture1.Height=224 Set BM.PictBox = Picture1 BM.GetPixels 'Now the unexpected happens. 'The GDI API INCORRECTLY reads the new larger size of Picture1 and as a result it "thinks" that the height hasn't changed, 'so while the first MsgBox shows "256", second one INCORRECTLY still shows "80"


Reply With Quote