' Empty GUI script created on 10-31-2011 + 11-03-2011, 15:32:15 by largo_winch (ThinAIR)
'--------------> GDIPLUS TEST FOR THINBASIC -------------------->
'-- modified by frank for largo about question of "transparence modus" for images, 29.mai.2012 :)
Uses "UI", "console"
'---------------------------->
#INCLUDE "GDIPLUS_LW1a.INC"
'---------------------------->
Begin ControlID
%Canvas_Gdip
%bClose
End ControlID
Type BGRA
B As Byte
G As Byte
R As Byte
A As Byte
End Type
' ========================================================================================
' ========================================================================================
' Main
' ========================================================================================
Function TBMain() As Long
Local hr As Long
Local hDlg As DWord
Local hdc As DWord
Local token As DWord
Local StartupInput As GdiplusStartupInput
' Initialize GDI+
StartupInput.GdiplusVersion = 1
hr = GdiplusStartup(token, StartupInput, ByVal %NULL)
If hr Then
MsgBox "Error initializing GDI+"
Exit Function
End If
Dialog New 0, "tb_gdiplus DrawImage",-1,-1, 420, 270, _
%WS_POPUP Or %WS_VISIBLE Or _
%WS_CLIPCHILDREN Or %WS_CAPTION Or _
%WS_SYSMENU Or %WS_MINIMIZEBOX, 0 To hDlg
Dialog Show Modal hDlg, Call dlgProc
' Shutdown GDI+
GdiplusShutdown token
End Function
' ========================================================================================
' ========================================================================================
' Main Dialog procedure
' ========================================================================================
CallBack Function DlgProc() As Long
Local cx, cy As Long, hDc As Long
' -- Test for messages
Select Case CBMSG
Case %WM_INITDIALOG
' -- Place controls here
Dialog Pixels CBHNDL, 400, 250 To Units cx, cy
Control Add Canvas, CBHNDL, %Canvas_Gdip, "", 5, 5, cx+100, cy+100
Control Add Button, CBHNDL, %bClose, "Close", 80+cx, cy+5-84, 50, 18, Call bCloseProc
Canvas_Attach CBHNDL, %Canvas_Gdip, %TRUE
Canvas_Color Rgb(128, 255, 0), Rgb(0, 0, 0)
'Canvas_Clear(Rgb(0,0,0))
Canvas_Scale Pixels
Case %WM_PAINT
GDIP_DrawImage()
Canvas_Redraw
Case %WM_COMMAND
Select Case CBCTL
Case %IDCANCEL
If CBCTLMSG = %BN_CLICKED Then Dialog End CBHNDL, 0
End Select
End Select
End Function
' -- Callback for close button
CallBack Function bCloseProc()
If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If
End Function
'--------------------> ~~~~~~~~~
Sub GDIP_DrawImage() ' SETPIXEL
'--------------------> ~~~~~~~~~
Local hStatus As Long
Local pGraphics As DWord
Local pImage As DWord
Local strFileName As String
Local nWidth As Long
Local nHeight As Long
Local rows As Long
Local cols As Long
Local pixelColor As Long
hStatus = GdipCreateFromHDC(Canvas_GetDC, pGraphics)
' // Create the Image object
strFileName = Ucode$("Metallica1a.jpg")
hStatus = GdipLoadImageFromFile(StrPtr(strFileName), pImage)
' // Draw the image
hStatus = GdipDrawImage(pGraphics, pImage, 10, 10)
' // Get the width and height of the bitmap
hStatus = GdipGetImageWidth(pImage, nWidth ) '(varptr(nWidth))
hStatus = GdipGetImageHeight(pImage, nHeight ) '(varptr(nHeigth))
'--------- // that's important! ------------ //
'pixelColor = GDIP_ARGB(255, 0, 255, 0) 'green pixeled
pixelColor = GDIP_ARGB(0, 255, 0, 255) '=> transparence modus !!!
'--------- // that's important! ------------ //
' // Create a checkered pattern with black pixels.
For rows = 1 To nWidth - 1 Step 2
For cols = 1 To nHeight Step 2
hStatus = GdipBitmapSetPixel(pImage, rows, cols, pixelColor)
Next
Next
' // Draw the altered bitmap.
hStatus = GdipDrawImage(pGraphics, pImage, 200, 200)
' // Cleanup
If pImage Then GdipDisposeImage(pImage)
If pGraphics Then GdipDeleteGraphics(pGraphics)
End Sub
you find solution in zip folder with your own gdip include file.
Bookmarks