Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDC_Graphic = 500 : %IDC_Button = 600
Global hDlg As Dword, bmp$
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,500,350, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Histogram", 50,10,100,20
Control Add Graphic, hDlg, %IDC_Graphic, "", 10,40,454,291
Graphic Attach hDlg, %IDC_Graphic
Graphic Render "baby.bmp", (0,0)-(453,290)
Graphic Get Bits To bmp$
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = %IDC_Button Then Histogram(400,200)
End Function
Sub Histogram(imgW As Long, imgH As Long)
'create histogram from content of bmp$
Local bp As Byte Pointer, i,pCount,Rmax,Gmax,Bmax As Long, hGW As Dword, sR,sG,sB As Single
Dim R(255) As Long, G(255) As Long, B(255) As Long
pCount = imgW*imgH
bp = StrPtr(bmp$)+8 'starting position for pixel data in string
For i = 0 To ImgW*ImgH - 1
Incr B(@bp) : Bmax = Max(Bmax,B(@bp)) : Incr bp
Incr G(@bp) : Gmax = Max(Gmax,G(@bp)) : Incr bp
Incr R(@bp) : Rmax = Max(Rmax,R(@bp)) : Incr bp
Incr bp 'no A histogram
Next i
'plot data
Graphic Window "Histogram", 500,500,300,450 To hGW
Graphic Attach hGW,0
Graphic Box (19,20)-(277,132),,%Black : Graphic Box (19,170)-(277,282),,%Black : Graphic Box (19,322)-(277,432),,%Black
sR = 100 / Rmax : sG = 100 / Gmax : sB = 100 / Bmax
For i = 0 To 255
Graphic Line (20+i,130)-(20+i,130-sR*R(i)),%Red
Graphic Line (20+i,280)-(20+i,280-sG*G(i)),%Green
Graphic Line (20+i,430)-(20+i,430-sB*B(i)),%Blue
Next i
'return graphic focus to the graphic control
Graphic Attach hDlg, %IDC_Graphic
End Sub
'gbs_00919
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm