PDA

View Full Version : canvas load images (simple way)



largo_winch
06-03-2013, 20:07
here I show a little example how to load images (pictures) in canvas (ui) mode:


' Empty GUI script created on 03-06-2013 12:58:08 by largo_winch (thinAir)


Uses "console", "ui"
Begin Const
%btnone=100
%btntwo
%bImage
%bImage2
%tAnimationTimer
End Const


Global hDlg As DWord


Function TBMain() As Long
Dialog New Pixels, 0, "Canvas LoadImage Test Code",-1,-1,450,350, %WS_OVERLAPPEDWINDOW To hDlg
Control Add Button, hDlg, %btnone,"Load Image", 20,10,160,24
Control Add Button, hDlg, %btntwo,"Load another Image", 220,10,160,24
Control Add Canvas, hDlg, %bImage,"", 20,60,360,280
'Control Add Canvas, hDlg, %bImage2,"", 20,140,160,220
Dialog Show Modal hDlg Call DlgProc
End Function


CallBack Function dlgProc()
Local sImageSmall As String = APP_SourcePath+"Prometh2aa.bmp"
Local sImageSmall2 As String = APP_SourcePath+"Alien1.bmp"
Local sImageSmall3 As String = APP_SourcePath+"AlienBig1.bmp"
Local w As Long, h As Long, hBMP As DWord


Select Case CBMSG


Case %WM_INITDIALOG
Dialog Set Timer CBHNDL, %tAnimationTimer, 10, %NULL
Control Add Canvas, CBHNDL, %bImage,"", 20, 70, w, h, %WS_BORDER
Canvas_Attach (CBHNDL, %bImage, TRUE)
Canvas_Scale Pixels
Canvas_BitmapRender(sImageSmall)
'------------ alternative way of going fine ---------- '
'Canvas_SetPos(10,100)
'Canvas_BitmapRender(sImageSmall2)

'Canvas_SetPos(50,120)
'Canvas_BitmapRender(sImageSmall3)
'------------ alternative way of going fine ---------- '

Case %WM_TIMER
Local tx, ty As Long
Canvas_Attach(CBHNDL, %bImage, %TRUE)
Canvas_Redraw ' ! -- Important: Needs this to sync

Case %WM_Command
If CBWPARAM = %btnone Then
Canvas_SetPos(1,100)
Canvas_BitmapRender(sImageSmall2)
End If

If CBWPARAM = %btntwo Then
Canvas_SetPos(100,20)
Canvas_BitmapRender(sImageSmall3)
End If

Case %WM_CLOSE


End Select


End Function





bye, largo