해결책을 찾기 위해 많은 시간을 할애하지만 할 수는 없습니다. 네가 나를 도울 수 있기를 바랍니다. 코드가 좀 더 길어서 여기에 문제가있는 부분 만 알려줍니다. 내 코드는 윈도우에서 비트 맵을 캡처하고 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가 빈 이미지를 생성한다는 것을 알았지 만, 내가 한 그림을 확인하기 위해 어떻게 마무리해야합니까? GhipCreateBitmapFromHBITMAP() 및 GdipGetImageGraphicsContext() 근처에있는이 단계가 정확합니까? 아니면 뭔가 추가해야합니까? 작동 방법?
PS : HBitmap에 이미 창 그림이 있습니다. . 그것을 확인 내 눈에
나는 koh의 단계를 밟았는데,이 내용은 AHK http://ahkscript.org/boards/viewtopic.php?f=5&t=3458에 작성되었습니다. AHK 코드를 테스트 한 결과 작동했습니다. 그런 다음 AHK 라이브러리의 함수를 사용하여 C++로 같은 순서로 작성했습니다. 그러나 C++은 조금 다릅니다. IMHO 명령문의 순서는 AHK와 동일하게 유지되어야합니다. Ad3)은 GdipGetImageGraphicsContext에서 완료된 GdipCreateBitmapFromHBITMAP ad4)에서 수행됩니다 (하지만 이는 잘못된 것입니다). – user1141649