GDIPlus Image Rotation (Petr)

Category: Graphics - GDI+

Date: 02-16-2022

Return to Index


 
'Compilable Example:  (Jose Includes)
' ========================================================================================
' GDI+ World transformation
' 99.9% based on Jos� Roca examples on GDI+ :)
' ========================================================================================
 
' SED_PBWIN
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "gdiplus_simple.inc"
 
%IDC_GRAPHIC  = 101
%MatrixOrderPrepend = 0
 
Sub GDIP_DrawRotatedImage (ByVal hdc AS DWord)
 
   Local pGraphics AS DWord
   Local pImage AS DWord
   Local strFileName As String
 
   GdipCreateFromHDC(hdc, pGraphics)
 
   strFileName = UCODE$(EXE.PATH$+"\ruler.bmp")
   GdipLoadImageFromFile(STRPTR(strFileName), pImage)
 
   ' -- Move to center
   GdipTranslateWorldTransform(pGraphics, 250.0!, 250.0!, %MatrixOrderPrepend)
   ' -- Turn
   GdipRotateWorldTransform(pGraphics, -45.0!, %MatrixOrderPrepend)
   ' -- Push back to make it turn around center
   GdipTranslateWorldTransform(pGraphics, -300.0/2!, -300.0/2!, %MatrixOrderPrepend)
 
   GdipDrawImage(pGraphics, pImage, 0, 0)
 
   ' // Cleanup
   IF pImage THEN GdipDisposeImage(pImage)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)
 
End Sub
   ' ========================================================================================
 
   ' ========================================================================================
   ' Main
   ' ========================================================================================
 
Function WINMAIN (ByVal hInstance AS DWordByVal hPrevInstance AS DWordByVal lpszCmdLine As AsciiZ PTRByVal nCmdShow As LongAs 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
 
   ' Create a new dialog
   DIALOG NEW PIXELS, 0, "GdipRotateTextureTransform", , , 500, 500, %WS_SYSMENU TO hDlg
 
   ' Add a graphic control
   CONTROL ADD GRAPHIC, hDlg, %IDC_GRAPHIC,"", 0, 0, 500, 500
   ' Select the drawing target
   GRAPHIC ATTACH hDlg, %IDC_GRAPHIC
   ' Set the foreground and background color
   GRAPHIC COLOR %BLACK, %WHITE
   ' Clear the entire selected graphic window
   GRAPHIC CLEAR
   ' Retrieve the handle of the device context
   GRAPHIC GET DC TO hdc
   ' Draw the graphics
   GDIP_DrawRotatedImage(hdc)
 
   DIALOG SHOW MODAL hDlg, CALL DlgProc
 
   ' Shutdown GDI+
   GdiplusShutdown token
 
End Function
   ' ========================================================================================
 
   ' ========================================================================================
   ' Main Dialog procedure
   ' ========================================================================================
 
CallBack Function DlgProc() As Long
 
   SELECT CASE CBMSG
 
      CASE %WM_COMMAND
         SELECT CASE CBCTL
            CASE %IDCANCEL
               IF CBCTLMSG = %BN_CLICKED THEN DIALOG END CBHNDL, 0
         END SELECT
 
   END SELECT
 
End Function
   ' ======================
 
'gbs_00964
'Date: 03-10-2012


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm