VB 用GDI+ 如何实现图片的旋转?
VB用GDI+如何实现图片的旋转?听说GDI+旋转图形以后很平滑的没有锯齿,请问用VB如何实现?谢谢!请高手不吝赐教!在线等!分不够我再加!在网上找了半天都是C++写的看...
VB 用GDI+ 如何实现图片的旋转?听说GDI+旋转图形以后很平滑的 没有锯齿,请问用VB如何实现?谢谢 !请高手不吝赐教!在线等!分不够我再加!在网上找了半天 都 是C++写的 看不懂!最好是VB
swx1995大哥 你图片处理的很好 ,就是边缘还有锯齿 ,你再给我搞搞好吗?分给你加到150也行啊 谢谢哦~~ 展开
swx1995大哥 你图片处理的很好 ,就是边缘还有锯齿 ,你再给我搞搞好吗?分给你加到150也行啊 谢谢哦~~ 展开
展开全部
图形平滑,边缘可不平滑
模块:
Option Explicit
Public Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatus
Public 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 GpStatus
Public Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As GpStatus
Public Declare Function GdipSetSmoothingMode Lib "gdiplus" (ByVal graphics As Long, ByVal SmoothingMd As SmoothingMode) As GpStatus
Public Declare Function GdipSetInterpolationMode Lib "gdiplus" (ByVal graphics As Long, ByVal interpolation As InterpolationMode) As GpStatus
Public 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 GpStatus
Public 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 GpStatus
Public Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As GpStatus
Public Declare Function GdipGetImageWidth Lib "gdiplus" (ByVal Image As Long, Width As Long) As GpStatus
Public Declare Function GdipGetImageHeight Lib "gdiplus" (ByVal Image As Long, Height As Long) As GpStatus
Public 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 = 1
End Enum
Public Enum QualityMode
QualityModeInvalid = -1
QualityModeDefault = 0
QualityModeLow = 1
QualityModeHigh = 2
End Enum
Public Enum SmoothingMode
SmoothingModeInvalid = QualityModeInvalid
SmoothingModeDefault = QualityModeDefault
SmoothingModeHighSpeed = QualityModeLow
SmoothingModeHighQuality = QualityModeHigh
SmoothingModeNone
SmoothingModeAntiAlias
End Enum
Public Enum InterpolationMode
InterpolationModeInvalid = QualityModeInvalid
InterpolationModeDefault = QualityModeDefault
InterpolationModeLowQuality = QualityModeLow
InterpolationModeHighQuality = QualityModeHigh
InterpolationModeBilinear
InterpolationModeBicubic
InterpolationModeNearestNeighbor
InterpolationModeHighQualityBilinear
InterpolationModeHighQualityBicubic
End Enum
Public Enum CompositingQuality
CompositingQualityInvalid = QualityModeInvalid
CompositingQualityDefault = QualityModeDefault
CompositingQualityHighSpeed = QualityModeLow
CompositingQualityHighQuality = QualityModeHigh
CompositingQualityGammaCorrected
CompositingQualityAssumeLinear
End Enum
Public Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End 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 = 20
End Enum
窗体(AutoRedraw=True)
Option Explicit
Dim token As Long
Dim 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 If
End Sub
Private Sub TerminateGDIPlus()
GdipDisposeImage img
GdipDeleteGraphics graphics
GdiplusShutdown token
End 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, 200
End 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, h
End Sub
Private Sub Form_Unload(Cancel As Integer)
TerminateGDIPlus
End Sub
模块:
Option Explicit
Public Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatus
Public 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 GpStatus
Public Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As GpStatus
Public Declare Function GdipSetSmoothingMode Lib "gdiplus" (ByVal graphics As Long, ByVal SmoothingMd As SmoothingMode) As GpStatus
Public Declare Function GdipSetInterpolationMode Lib "gdiplus" (ByVal graphics As Long, ByVal interpolation As InterpolationMode) As GpStatus
Public 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 GpStatus
Public 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 GpStatus
Public Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As GpStatus
Public Declare Function GdipGetImageWidth Lib "gdiplus" (ByVal Image As Long, Width As Long) As GpStatus
Public Declare Function GdipGetImageHeight Lib "gdiplus" (ByVal Image As Long, Height As Long) As GpStatus
Public 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 = 1
End Enum
Public Enum QualityMode
QualityModeInvalid = -1
QualityModeDefault = 0
QualityModeLow = 1
QualityModeHigh = 2
End Enum
Public Enum SmoothingMode
SmoothingModeInvalid = QualityModeInvalid
SmoothingModeDefault = QualityModeDefault
SmoothingModeHighSpeed = QualityModeLow
SmoothingModeHighQuality = QualityModeHigh
SmoothingModeNone
SmoothingModeAntiAlias
End Enum
Public Enum InterpolationMode
InterpolationModeInvalid = QualityModeInvalid
InterpolationModeDefault = QualityModeDefault
InterpolationModeLowQuality = QualityModeLow
InterpolationModeHighQuality = QualityModeHigh
InterpolationModeBilinear
InterpolationModeBicubic
InterpolationModeNearestNeighbor
InterpolationModeHighQualityBilinear
InterpolationModeHighQualityBicubic
End Enum
Public Enum CompositingQuality
CompositingQualityInvalid = QualityModeInvalid
CompositingQualityDefault = QualityModeDefault
CompositingQualityHighSpeed = QualityModeLow
CompositingQualityHighQuality = QualityModeHigh
CompositingQualityGammaCorrected
CompositingQualityAssumeLinear
End Enum
Public Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End 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 = 20
End Enum
窗体(AutoRedraw=True)
Option Explicit
Dim token As Long
Dim 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 If
End Sub
Private Sub TerminateGDIPlus()
GdipDisposeImage img
GdipDeleteGraphics graphics
GdiplusShutdown token
End 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, 200
End 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, h
End Sub
Private Sub Form_Unload(Cancel As Integer)
TerminateGDIPlus
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
GDI功能很强大哦。
有关知识非常多
有关知识非常多
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询