模块: Option Explicit Public Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatusPublic Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As GpStatus Public Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, graphics As Long) As GpStatusPublic Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As GpStatusPublic Declare Function GdipSetSmoothingMode Lib "gdiplus" (ByVal graphics As Long, ByVal SmoothingMd As SmoothingMode) As GpStatusPublic Declare Function GdipSetInterpolationMode Lib "gdiplus" (ByVal graphics As Long, ByVal interpolation As InterpolationMode) As GpStatusPublic Declare Function GdipSetCompositingQuality Lib "gdiplus" (ByVal graphics As Long, ByVal CompositingQlty As CompositingQuality) As GpStatus Public Declare Function GdipRotateWorldTransform Lib "gdiplus" (ByVal graphics As Long, ByVal angle As Single, ByVal order As MatrixOrder) As GpStatusPublic Declare Function GdipTranslateWorldTransform Lib "gdiplus" (ByVal graphics As Long, ByVal dx As Single, ByVal dy As Single, ByVal order As MatrixOrder) As GpStatus Public Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal filename As Long, Image As Long) As GpStatusPublic Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As GpStatusPublic Declare Function GdipGetImageWidth Lib "gdiplus" (ByVal Image As Long, Width As Long) As GpStatusPublic Declare Function GdipGetImageHeight Lib "gdiplus" (ByVal Image As Long, Height As Long) As GpStatusPublic Declare Function GdipDrawImageRect Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal x As Single, ByVal y As Single, ByVal Width As Single, ByVal Height As Single) As GpStatus Public Enum MatrixOrder MatrixOrderPrepend = 0 MatrixOrderAppend = 1End Enum Public Enum QualityMode QualityModeInvalid = -1 QualityModeDefault = 0 QualityModeLow = 1 QualityModeHigh = 2End Enum Public Enum SmoothingMode SmoothingModeInvalid = QualityModeInvalid SmoothingModeDefault = QualityModeDefault SmoothingModeHighSpeed = QualityModeLow SmoothingModeHighQuality = QualityModeHigh SmoothingModeNone SmoothingModeAntiAliasEnd Enum Public Enum InterpolationMode InterpolationModeInvalid = QualityModeInvalid InterpolationModeDefault = QualityModeDefault InterpolationModeLowQuality = QualityModeLow InterpolationModeHighQuality = QualityModeHigh InterpolationModeBilinear InterpolationModeBicubic InterpolationModeNearestNeighbor InterpolationModeHighQualityBilinear InterpolationModeHighQualityBicubicEnd Enum Public Enum CompositingQuality CompositingQualityInvalid = QualityModeInvalid CompositingQualityDefault = QualityModeDefault CompositingQualityHighSpeed = QualityModeLow CompositingQualityHighQuality = QualityModeHigh CompositingQualityGammaCorrected CompositingQualityAssumeLinearEnd Enum Public Type GdiplusStartupInput GdiplusVersion As Long DebugEventCallback As Long SuppressBackgroundThread As Long SuppressExternalCodecs As LongEnd Type Public Enum GpStatus Ok = 0 GenericError = 1 InvalidParameter = 2 OutOfMemory = 3 ObjectBusy = 4 InsufficientBuffer = 5 NotImplemented = 6 Win32Error = 7 WrongState = 8 Aborted = 9 FileNotFound = 10 ValueOverflow = 11 AccessDenied = 12 UnknownImageFormat = 13 FontFamilyNotFound = 14 FontStyleNotFound = 15 NotTrueTypeFont = 16 UnsupportedGdiplusVersion = 17 GdiplusNotInitialized = 18 PropertyNotFound = 19 PropertyNotSupported = 20End Enum 窗体(AutoRedraw=True)Option Explicit Dim token As LongDim graphics As Long Dim img As Long, w As Long, h As Long Private Sub InitGDIPlus() Dim uInput As GdiplusStartupInput uInput.GdiplusVersion = 1 If GdiplusStartup(token, uInput) <> Ok Then MsgBox "GDI+ 初始化错误。程序即将关闭。", vbCritical, "InitError" End End IfEnd Sub Private Sub TerminateGDIPlus() GdipDisposeImage img GdipDeleteGraphics graphics GdiplusShutdown tokenEnd Sub Private Sub Form_Load() InitGDIPlus GdipCreateFromHDC Me.hDC, graphics ‘GdipSetSmoothingMode graphics, SmoothingModeAntiAlias ‘GdipSetInterpolationMode graphics, InterpolationModeHighQuality ‘GdipSetCompositingQuality graphics, CompositingQualityHighQuality GdipLoadImageFromFile StrPtr(App.Path & "\1.png"), img GdipGetImageWidth img, w GdipGetImageHeight img, h Rotate 15, graphics, 200, 200End Sub Sub Rotate(angle As Single, g As Long, x As Single, y As Integer) GdipRotateWorldTransform g, angle, MatrixOrderAppend GdipTranslateWorldTransform g, x, y, MatrixOrderAppend GdipDrawImageRect g, img, -w, -h / 2, w, hEnd Sub Private Sub Form_Unload(Cancel As Integer) TerminateGDIPlusEnd Sub
时间: 2024-11-09 01:43:45