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_gSource = 500
%IDC_gTarget = 600
%IDC_Button = 700
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Graphic Control Test",300,300,730,610, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %IDC_gSource,"", 10,10,100,100, %WS_Border
Control Add Button, hDlg, %IDC_Button,"Ascii",10,130,60,20
Graphic Attach hDlg, %IDC_gSource
Graphic Render "cowgirl.bmp", (0,0)-(99,99)
Control Add Graphic, hDlg, %IDC_gTarget,"", 130,10,590,590, %WS_Border
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = %IDC_Button And Cb.CtlMsg = %STN_Clicked Then CreateAsciiArt(%IDC_gSource, %IDC_gTarget)
End Function
Sub CreateAsciiArt(gIn As Dword, gOut As Dword)
'for each pixel, add a random 0/1, colored to match that of the pixel
Local hFont As Dword, i,j,x,y,w,h,iCount,pWidth,pHeight As Long, bmp$
Local PixelPtr As Long Ptr, t As String
Graphic Get Bits To bmp$ 'color data from image
w = Cvl(bmp$,1) : h = Cvl(bmp$,5)
PixelPtr = StrPtr(bmp$) + 8
Graphic Attach hDlg, %IDC_gTarget, ReDraw 'set target font to fixed-width
Font New "Courier New", 4 To hFont
Graphic Set Font hFont
Graphic Text Size "0" To pWidth, pHeight
For i = 1 To w*h
Graphic Color RGB(@PixelPtr)
Incr PixelPtr : Incr iCount
Graphic Get Pos To x,y
Graphic Set Pos ((i Mod w)*pHeight,y)
Graphic Print Chr$(Rnd(65,90));
If iCount Mod w = 0 Then Graphic Print
Next
Graphic ReDraw
End Sub
'gbs_00857
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm