掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
VBAで、GDI+を使って画像を回転させるには? (ID:141085)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
ありがとうございました。 おかげさまで、うまく回転ができました。 中味はこれから勉強させていただきますが、とりあえず今日出来たところをお知らせいたします。 Private Sub RotateImage(ByRef hImage As Long, ByRef imgImage As Long, ByVal angle As Single, Optional lBackColour As Long = -1) Dim retval As Long Dim lHeight As Long, lWidth As Long Dim newHeight As Long, newWidth As Long Dim hBrush As Long Dim imgGraphics As Long Const pi As Single = 3.14159265 retval = GdipGetImageHeight(hImage, lHeight) retval = GdipGetImageWidth(hImage, lWidth) '新しい画像に最低限必要なサイズ算出 newWidth = lWidth * Abs(Cos(angle * pi / 180)) + lHeight * Abs(Sin(angle * pi / 180)) newHeight = lWidth * Abs(Sin(angle * pi / 180)) + lHeight * Abs(Cos(angle * pi / 180)) '; オフスクリーンバッファ Image、Graphics 作成 PixelFormat32bppARGB = 10 Or BitShift(32, 8) Or PixelFormatAlpha Or PixelFormatGDI Or PixelFormatCanonical retval = GdipCreateBitmapFromScan0(newWidth, newHeight, 0, PixelFormat32bppARGB, ByVal 0&, imgImage) retval = GdipGetImageGraphicsContext(imgImage, imgGraphics) retval = GdipCreateSolidFill(lBackColour, hBrush) retval = GdipFillRectangle(imgGraphics, hBrush, 0, 0, newWidth, newHeight) retval = GdipDeleteBrush(hBrush) '回転 retval = GdipTranslateWorldTransform(imgGraphics, -lWidth / 2, -lHeight / 2, MatrixOrderAppend) retval = GdipRotateWorldTransform(imgGraphics, angle, MatrixOrderAppend) retval = GdipTranslateWorldTransform(imgGraphics, newWidth / 2, newHeight / 2, MatrixOrderAppend) retval = GdipDrawImageRectRectI(imgGraphics, hImage, 0, 0, lWidth, lHeight, 0, 0, lWidth, lHeight, UnitPixel, 0, 0, 0) retval = GdipDeleteGraphics(imgGraphics) retval = GdipDisposeImage(hImage) End Sub
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.