VANYA
Anmeldungsdatum: 17.06.2011 Beiträge: 8
|
Verfasst am: 17.04.2012, 07:18 Titel: |
|
|
arduno hat Folgendes geschrieben: | Hallo, ich finde deine Demo mit GDI+ klasse.
Ich habe mich da nie ran getraut.
Könntest du auch mal eine Demo herstellen, wo eine Bitmap gedreht (Rotate) wird und Transparent ist. Und der Rotationspunkt XY beliebig gewählt werden kann innerhalb der Bitmapgrösse?
Danke.
Gruss |
Code: | #Include "windows.bi"
#Include "win/gdiplus.bi"
Using GDIPLUS
Dim wc As WNDCLASSEX
Dim msg As MSG
Dim ULONG_PTR_01 As ULONG_PTR
Dim GDIPLUSSTARTUPINPUT_01 As GDIPLUSSTARTUPINPUT
GDIPLUSSTARTUPINPUT_01.GdiplusVersion = 1
If (GdiplusStartup(@ULONG_PTR_01, @GDIPLUSSTARTUPINPUT_01, NULL) <> 0) Then
Print "FAIL"
EndIf
Function Load_imageA(byval path as String) as Any Ptr
DIM GPIMAGE_01 AS GPBITMAP PTR
Var blen = (Len(path)*2)+2
Dim As WString Ptr wbuf
wbuf = Allocate( blen )
MultiByteToWideChar(CP_ACP, 0, path, -1, wbuf, blen)
IF (GDIPLOADIMAGEFROMFILE( *wbuf, @GPIMAGE_01) <> 0) THEN
PRINT "FAIL"
End If
DeAllocate(wbuf)
Return GPIMAGE_01
end Function
Sub OnPaint(compHdc As HDC,hbmpSource As PVOID,gp_ As PVOID)
Dim As PVOID GpGraphics,hbmpDest
Dim As UInteger Wsource,Hsource,WDest,HDest
Dim As Integer X = 50 , Y = 50 , Xr = 50 , Yr = 50
Static As Single angle,Xscale,Yscale
Xscale = angle/300
Yscale = Xscale
GdipCreateBitmapFromScan0(100, 100, NULL, PixelFormat32bppARGB, NULL, @hbmpDest)
GdipCreateFromHDC(compHdc,@GpGraphics)
GdipGetImageWidth(hbmpSource,@Wsource)
GdipGetImageHeight(hbmpSource,@Hsource)
GdipGetImageWidth(Cast(GpIMAGE Ptr,hbmpDest),@WDest)
GdipGetImageHeight(Cast(GpIMAGE Ptr,hbmpDest),@HDest)
GdipDrawImageRect(GpGraphics,gp_ , 0, 0,Wdest,Hdest)
If Xscale<>0 Then
GdipScaleWorldTransform(GpGraphics,Xscale,Yscale,MatrixOrderAppend)
EndIf
GdipRotateWorldTransform(GpGraphics, angle, 1)
GdipTranslateWorldTransform(GpGraphics, X, Y, 1)
GdipDrawImageRectI(GpGraphics,hbmpSource , Xr , Yr , -Wsource, -Hsource)
GdipResetWorldTransform(GpGraphics)
angle= angle+3
If angle>=360 Then angle=0
GdipDisposeImage(hbmpDest)
GdipDeleteGraphics(GpGraphics)
End Sub
Function WndProc(hWnd As HWND,uMsg As UINT,wParam As WPARAM,lParam As LPARAM) As Integer
Dim ps As PAINTSTRUCT
Static As HDC compHdc,hdc
Static As PVOID hbmpSource,gp_
Select Case uMsg
Case WM_CLOSE
GdipDisposeImage(gp_)
GdipDisposeImage(hbmpSource)
KillTimer(hwnd,1)
DeleteDC(compHdc)
PostQuitMessage(0)
Case WM_TIMER
OnPaint(compHdc,hbmpSource,gp_)
InvalidateRect(hwnd,0,0)
Case WM_CREATE
gp_=Load_imageA("BG.png")
hbmpSource=Load_imageA("source.png")
hdc=GetDC(GetDesktopWindow)
compHdc=CreateCompatibleDC(hdc)
Var bitmap = CreateCompatibleBitmap(hdc,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN))
SelectObject(compHdc,bitmap)
DeleteObject(bitmap)
ReleaseDC(GetDesktopWindow,hdc)
SetTimer(hwnd,1,10,0)
Case WM_PAINT
BeginPaint(hWnd,@ps)
BitBlt(ps.hdc,ps.rcPaint.left,ps.rcPaint.top,ps.rcPaint.right-ps.rcPaint.left,ps.rcPaint.bottom-ps.rcPaint.top,compHdc,ps.rcPaint.left,ps.rcPaint.top,SRCCOPY)
EndPaint(hWnd,@ps)
Return 0
Case Else
Return DefWindowProc(hWnd,uMsg,wParam,lParam)
End Select
End Function
With wc
.hInstance=GetModuleHandle(0)
.cbSize=SizeOf(WNDCLASSEX)
.style=CS_HREDRAW Or CS_VREDRAW
.lpfnWndProc=@WndProc
.lpszClassName=StrPtr("class")
.hCursor=LoadCursor(NULL,IDC_ARROW)
End With
RegisterClassEx(@wc)
CreateWindowEx(0,wc.lpszClassName,"DrawGDI+",WS_OVERLAPPEDWINDOW Or WS_VISIBLE,200,200,280,255,0,0,wc.hInstance,0)
While GetMessage(@msg,0,0,0)
TranslateMessage(@msg)
DispatchMessage(@msg)
Wend |
Download project _________________ http://free-basic.ru/ - Russian FreeBasic site |
|