掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
VBAで、GDI+を使って画像を回転させるには? (ID:141083)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
PixelFormat32bppARGBを後押ししていただいたので、VB6のコードを検索してみた結果、 retval = GdipCreateBitmapFromScan0(300, 300, 0, PixelFormat32bppARGB, ByVal 0&, imgImage) とすると、エラーにならない事が判明しました。(理屈は分かりませんが) 手直ししたコードは下記の通りです。これにより、枠は大きくなりましたが、 GdipDrawImageRectI で貼り付けた画像は枠に合わせて大きくなってしまっています。引き続きアドバイスをお願いいたします。 '大きいサイズのImageを別にimgImageで戻す様にした Public Function 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 Dim lWidth As Long Dim hBrush As Long Dim imgGraphics As Long retval = GdipGetImageHeight(hImage, lHeight) retval = GdipGetImageWidth(hImage, lWidth) If angle > 0 And angle < 360 Then angle = angle - 180 '; オフスクリーンバッファ Image、Graphics 作成 PixelFormat32bppARGB = 10 Or BitShift(32, 8) Or PixelFormatAlpha Or PixelFormatGDI Or PixelFormatCanonical retval = GdipCreateBitmapFromScan0(300, 300, 0, PixelFormat32bppARGB, ByVal 0&, imgImage) retval = GdipGetImageGraphicsContext(imgImage, imgGraphics) retval = GdipCreateSolidFill(lBackColour, hBrush) retval = GdipFillRectangle(imgGraphics, hBrush, 0, 0, 300, 300) retval = GdipDeleteBrush(hBrush) retval = GdipRotateWorldTransform(imgGraphics, angle, MatrixOrderPrepend) '数字は試行錯誤の途中 retval = GdipDrawImageRectI(imgGraphics, hImage, lWidth / 2, lHeight / 2, -500, -400) retval = GdipDeleteGraphics(imgGraphics) retval = GdipDisposeImage(hImage) End Function
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.