我花了很多时间试图找到解决方案,但不能。我希望你能帮助我。代码有点长,所以我只给出我遇到问题的部分。我的代码从窗口捕获位图并将其保存在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