我花了很多時間試圖找到解決方案,但不能。我希望你能幫助我。代碼有點長,所以我只給出我遇到問題的部分。我的代碼從窗口捕獲位圖並將其保存在HBitmap中。我需要旋轉位圖。所以我啓動GDI +並從HBitmap創建位圖pBitmap:圖像處理:位圖旋轉(C++/GDI +)
// INIT GDI
ULONG_PTR gdiplusToken;
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
if (!gdiplusToken) return 3;
// Gdip_GetRotatedDimensions:
GpBitmap* pBitmap;
int result = Gdiplus::DllExports::GdipCreateBitmapFromHBITMAP(HBitmap, 0, &pBitmap);
然後我計算旋轉所需的變量。然後,我創建的圖形對象,並試圖旋轉圖像:
GpGraphics * pG;
result = Gdiplus::DllExports::GdipGetImageGraphicsContext(pBitmap, &pG);
Gdiplus::SmoothingMode smooth = SmoothingModeHighQuality;
result = Gdiplus::DllExports::GdipSetSmoothingMode(pG, smooth);
Gdiplus::InterpolationMode interpolation = InterpolationModeNearestNeighbor;
result = Gdiplus::DllExports::GdipSetInterpolationMode(pG, interpolation);
MatrixOrder MatrixOrder_ = MatrixOrderPrepend;
result = Gdiplus::DllExports::GdipTranslateWorldTransform(pG, xTranslation, yTranslation, MatrixOrder_);
MatrixOrder_ = MatrixOrderPrepend;
result = Gdiplus::DllExports::GdipRotateWorldTransform(pG, ROTATION_ANGLE, MatrixOrder_);
GpImageAttributes * ImgAttributes;
result = Gdiplus::DllExports::GdipCreateImageAttributes(&ImgAttributes); // create an ImageAttribute object
result = Gdiplus::DllExports::GdipDrawImageRectRect(pG,pBitmap,0,0,w,h,0,0,w,h,UnitPixel,ImgAttributes,0,0); // Draw the original image onto the new bitmap
result = Gdiplus::DllExports::GdipDisposeImageAttributes(ImgAttributes);
最後,我想檢查圖像,所以我說:
CLSID pngClsid;
GetEncoderClsid(L"image/png", &pngClsid);
result = Gdiplus::DllExports::GdipCreateBitmapFromGraphics(w, h, pG, &pBitmap);
result = Gdiplus::DllExports::GdipSaveImageToFile(pBitmap, L"justest.png", &pngClsid, NULL); // last voluntary? GDIPCONST EncoderParameters* encoderParams
但我的形象是空白。我發現GdipCreateBitmapFromGraphics會創建空白圖像,但我應該如何完成它以檢查我所做的圖紙?難道這些步驟正確(不只是在這裏,但上方,GdipCreateBitmapFromHBITMAP()和GdipGetImageGraphicsContext(附近)或我需要添加一些如何得到它的工作
PS:?我相信HBITMAP包含窗口的畫面,我已經。檢查它
我按照kon的步驟寫了這個文件在AHK http://ahkscript.org/boards/viewtopic.php?f=5&t=3458。我測試了AHK代碼,它工作。然後我使用AHK庫中的函數,並以相同的順序將它們寫入C++。但是C++有點不同。恕我直言,報表的順序應該保持不變,就像在AHK中一樣。 Ad3)在GdipGetImageGraphicsContext中完成(在GdipCreateBitmapFromHBITMAP ad4)中完成(但這可能是錯誤的) – user1141649