Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB5 getpixel for a picture loaded ina picturebox

Status
Not open for further replies.

G_X

Technical User
Mar 22, 2018
1
0
0
GR
Hi,
Although the program used to run smoothly on win98 and VB5 now cannot read the info about the window pixel and therefore cannot proceed
to calculate the Lab pixel values from RGB? The VB5 run fine for some other programs built with VB5 under Win10 environment.
Any ideas?
Following is the part of the program

Cheers

Public Sub Command1_Click()

Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hwndOwner = Me.hwnd
'Set the application's instance
OFName.hInstance = App.hInstance
'Select a filter
OFName.lpstrFilter = "Image Files (*.bmp;*.jpg;*.png)" + Chr$(0) + "*.bmp;*.jpg;*.png" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
'create a buffer for the file
OFName.lpstrFile = Space$(254)
'set the maximum length of a returned file
OFName.nMaxFile = 255
'Create a buffer for the file title
OFName.lpstrFileTitle = Space$(254)
'Set the maximum length of a returned file title
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the title
OFName.lpstrTitle = "Open File"
'No flags
OFName.flags = 0

'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
Label2 = Trim$(OFName.lpstrFile)

End If

End Sub

Private Sub Command2_Click()
Dim PicInfo As BITMAP
Dim pic As Picture
Dim X, Y As Long
Dim height, width As Long
Dim R As Long
Dim imagesource As String
Dim hFile As Long, FileInfo As BY_HANDLE_FILE_INFORMATION
Dim Red, Green, Blue As Variant
Dim Xcie, Ycie, Zcie As Double
Dim CIEL, CIEa, CIEb As Variant
Dim RATIOXcie, RATIOYcie, RATIOZcie As Double
Dim miL, mia, mib, maL, maa, mab As Double

imagesource = Label2.Caption
Set pic = LoadPicture(imagesource)
'Graphics formats recognized by VB include (bmp, icon, rle, wmf, emf, GIF _
jpg) files


' Load icon into a picturebox
Picture1.Picture = LoadPicture(imagesource)
Form1.WindowState = vbMaximized


'Get information (such as height and width) about the picturebox
GetObject pic.Handle, Len(PicInfo), PicInfo
Text1.Text = PicInfo.bmHeight
Text2.Text = PicInfo.bmWidth

'-----------------------------------------------------
hFile = Picture1.hDC
MsgBox "Window Handle: " + CStr(hFile), vbInformation
'-----------------------------------------------------
Open "C:\RGB Image Analyser\RGBVALUES.txt" For Output As 1#
Print #1, " Height Width RED GREEN BLUE"
Print #1, "(Pixel) (Pixel) L* a* b* "
Print #1, "------- ------- ---------------------------------"

height = PicInfo.bmHeight
width = PicInfo.bmWidth

maL = Text3.Text
maa = Text4.Text
mab = Text5.Text
miL = Text6.Text
mia = Text7.Text
mib = Text8.Text

For X = 0 To width - 1 Step 1
For Y = 0 To height - 1 Step 1

R = GetPixel(hFile, X, Y)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top