2014-05-22 2 views
0

해결책을 찾기 위해 많은 시간을 할애하지만 할 수는 없습니다. 네가 나를 도울 수 있기를 바랍니다. 코드가 좀 더 길어서 여기에 문제가있는 부분 만 알려줍니다. 내 코드는 윈도우에서 비트 맵을 캡처하고 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에 이미 창 그림이 있습니다. . 그것을 확인 내 눈에

답변

0

을, 당신은 당신의 접근 방식에서 뒤쪽으로 몇 가지를 가지고 당신이해야 할 일은 을 다음된다. 당신의 이미지에

  1. 읽기 (SRC)
  2. 이 최소 경계 찾기 회전 된 이미지를 포함 할 직사각형 (즉, 모서리와 최소 및 최대 x와 y 사이의 거리가 치수입니다.
  3. 원하는 크기와 픽셀 형식 (src와 같을 수도 있지만 원하는 알파 채널이있을 수 있음)과 원하는 배경색 (dst)을 사용하여 새 Image 객체를 만듭니다.
  4. dst new Graphics(dst))
  5. 적절한는
  6. 그리기 SRC DST에 그래픽에 변환 설정
  7. 수출 DST

좋은 소식은 확실히 당신이 바로 일을하고 있는지, 당신은 단계를 분리 할 수 ​​있습니다 . 예를 들어 이미지와 그래픽을 만들고 변환없이 선을 그릴 수 있습니다 (또는 X가있는 상자를 더 좋게 만들 수 있습니다). 당신이 기대하는 바가 있다면 올바른 길을 가고 있습니다. 다음으로 변환을 상자에 추가하십시오. 귀하의 경우 회전과 번역이 모두 필요합니다. 다음으로 회전에 적합한 대상 이미지의 크기를 가져옵니다 (protip : 사각형을 테스트하지 마십시오). 마지막으로 실제 이미지로 처리하십시오.

한 번에 모든 것을 얻으 려하지 않고 올바른 출력으로 단계별로 안내합니다.

+0

나는 koh의 단계를 밟았는데,이 내용은 AHK http://ahkscript.org/boards/viewtopic.php?f=5&t=3458에 작성되었습니다. AHK 코드를 테스트 한 결과 작동했습니다. 그런 다음 AHK 라이브러리의 함수를 사용하여 C++로 같은 순서로 작성했습니다. 그러나 C++은 조금 다릅니다. IMHO 명령문의 순서는 AHK와 동일하게 유지되어야합니다. Ad3)은 GdipGetImageGraphicsContext에서 완료된 GdipCreateBitmapFromHBITMAP ad4)에서 수행됩니다 (하지만 이는 잘못된 것입니다). – user1141649