GDI+를 이용한 회전 3가지.... | |||
| |||
우선 코드 길이가 짧습니다. ( 코딩시간이 줄어들죠... ^^.) 또한 보간모드가 기본적으로 포함되어 있습니다. ( 이미지 보간 함수를 직접 만든다면 엄청난 수학과 싸우셔야 됩니다. ) 회전시에는 보간모드를 조절하여 좋은 퀄리티의 보간모드를 사용하시면 더 좋습니다.( SetInterpolationMode() 함수 사용 ) 이 두가지 잇점만으로도 충분히 사용할 가치가 있다고 생각합니다.(어디까지나 제 주관입니다 --;; 물론 안 쓰셔도 무방합니다.) 제가 사용하는 세가지 방법을 적어보겠습니다.... ^^ 방법 1 Image Class 에 있는 RotateFlip( RotateFlipType rotateFlipType) 함수를 사용하시면 Image 객체 자체를 회전 시킬 수 있습니다. 다만 이를 이용해서는 정해진 각만 변환이 가능합니다. 또한, 미러 기능을 이용하실 수도 있습니다. rotateFlipType은 아래와 같은 종류가 있습니다. RotateNoneFlipNone Specifies no rotation and no flipping. Rotate90FlipNone Specifies a 90-degree rotation without flipping. Rotate180FlipNone Specifies a 180-degree rotation without flipping. Rotate270FlipNone Specifies a 270-degree rotation without flipping. RotateNoneFlipX Specifies no rotation and a horizontal flip. Rotate90FlipX Specifies a 90-degree rotation followed by a horizontal flip. Rotate180FlipX Specifies a 180-degree rotation followed by a horizontal flip. Rotate270FlipX Specifies a 270-degree rotation followed by a horizontal flip. RotateNoneFlipY Specifies no rotation and a vertical flip. Rotate90FlipY Specifies a 90-degree rotation followed by a vertical flip. Rotate180FlipY Specifies a 180-degree rotation followed by a vertical flip. Rotate270FlipY Specifies a 270-degree rotation followed by a vertical flip. RotateNoneFlipXY Specifies no rotation, a horizontal flip, and then a vertical flip. Rotate90FlipXY Specifies a 90-degree rotation followed by a horizontal flip and then a vertical flip. Rotate180FlipXY Specifies a 180-degree rotation followed by a horizontal flip and then a vertical flip. Rotate270FlipXY Specifies a 270-degree rotation followed by a horizontal flip and then a vertical flip. 간단한 예제를 보이자면... Image img("c: est.bmp") Graphics gx(hDC); gx.DrawImage(&img, 0, 0); img. RotateFlip( Rotate180FlipX ); gx.DrawImage(&img, 0, 0); 이 방법이 아닌 각도를 조절하시고 싶으시다면.... Graphics Class 를 사용하셔야 됩니다. 방법 2 Graphics 객체를 생성하신 후 RotateTransform()과 TranslateTransform()과 DrawImage() 함수를 사용하셔야 됩니다. int ix, iy; Bitmap bmp(L"c: est.bmp"); Bitmap tempbmp(bmp.GetWidth(), bmp.GetHeight(), PixelFormat24bppRGB); ix = int(bmp.GetWidth() / (-2.0)); iy = int(bmp.GetHeight() / (-2.0)); Graphics gx(hDC) Graphics tempgx(&tempbmp); tempgx.RotateTransform(50); tempgx.TranslateTransform(REAL(-ix), REAL(-iy), MatrixOrderAppend); Point dest[3] = {Point(ix, iy), Point(ix+bmp.GetWidth(), iy), Point(ix,iy+bmp.GetHeight())}; tempgx.DrawImage(&bmp, dest, 3, 0, 0, bmp.GetWidth(), bmp.GetHeight(), UnitPixel); gx.DrawImage(&tempbmp, 100, 100); 이런 정도로 쓰시면 되겠네요.... 방법 3 Graphics 객체를 생성하신 후 DrawImage() 함수를 사용하셔야 됩니다. Status DrawImage( Image* image, const Point* destPoints, // Point[3] INT count, // 3 INT srcx, INT srcy, INT srcwidth, INT srcheight, Unit srcUnit, // UnitPixel ImageAttributes* imageAttributes, // NULL &nBsp; DrawImageAbort callback, // NULL VOID* callbackData ); // NULL 여기서 제일 중요한 부분이 destPoints 의 값을 채워주는 부분입니다. Point[3] 의 값을 채워주면 이미지를 회전 시킬 수가 있습니다. 세 포인트 값의 계산은 님이 함수를 만드셔서 쓰시면 편하실겁니다. ^^ Bitmap bmp1(L"c:1.bmp"); // 원본 이미지 Graphics gx(hDC); gx.DrawImage(&bmp, 0, 0); // 회전 전 그리기 Point destPoints[3] = { Point(LeftTopX, LeftTopY), Point(RightTopX, RightTopY), Point(LeftBottomX, LeftBottomY) ) // 변환될 좌표 만들어주기 gx.DrawImage(bmp1,desPoints, 3,0,0,bmp1.GetWidth(),bmp1.GetHeight(), UnitPixel, NULL, NULL, NULL ); // 회전 후 그리기 Point 값 채우는 함수는 너무 이식성 없게 만들어놔서 붙여놓기가 좀 그렇네요. --; 꼭 필요하신 분이 계시다면 손을 좀 봐서 올려놓겠습니다. 이상 제가 회전할 때 사용하는 방법이었습니다... Tags: GDI+ 윈도우즈 | |||
| |||
| |||
Login for comment |
SIMILAR POSTS VC++ 6.0 에서 GDI+ 사용하기.. |
OTHER POSTS IN THE SAME CATEGORY MSN Live Messenger가 동작이 안되요 |