|
Graphics::TBitmap * 과 math.h 의 삼각함수를 이용하여 이미지 회전을 하는 함수입니다.
그러나 사용해 보시면 아시겠지만
90도의 배수인 90도 180도 270도 360도 ..... 이런 각도가 아니면
깨끗하게 나오지 않습니다.
왜그런지는 생각해보면 아실것인데....
그런부분에 대한 보정처리가 필요합니다만
아래 함수에는 되어있지 않습니다.
Graphic32에 image32를 사용해도 위 90도의 배각에서만 돌리는 함수가 있을것입니다.
혹 도움이 되길 기대합니다.
그럼...
//---------------------------------------------------------------------------
Graphics::TBitmap * __fastcall TForm1::Rotate(Graphics::TBitmap *bmp, float deg)
{
RGBTRIPLE *pt,*pt1;
double x=0,y=0;
int left=bmp->Width/2;
int right=bmp->Height/2;
int pixel = getpixel(bmp->PixelFormat);
double seta;
seta = DegToRad(deg);
Graphics::TBitmap *temp = new Graphics::TBitmap;
temp->Width = bmp->Width;
temp->Height = bmp->Height;
temp->PixelFormat = bmp->PixelFormat;
temp->Palette = CopyPalette(bmp->Palette);
int half_w=bmp->Width/2;
int half_h=bmp->Height/2;
temp->Canvas->Brush=bmp->Canvas->Brush;
temp->Canvas->FillRect(Rect(0,0,temp->Width,temp->Height));
float co = cos(seta); /* cosine 값 */
float si = sin(seta); /* sine 값 */
for(int Y = 0; Y < temp->Height; Y++)
{
pt1 = (RGBTRIPLE *)bmp->ScanLine[Y];
for(int X = 0; X < temp->Width; X++, pt1++)
{
x = (X-half_w)*co-((Y-half_h)*si)+half_w;
y = (Y-half_h)*co+((X-half_w)*si)+half_h;
int kx=int(x+0.5);
int ky=int(y+0.5);
if( kx >= 0 && kx < (temp->Width) && ky >= 0 && ky < (temp->Height))
{
pt = (RGBTRIPLE *)temp->ScanLine[ky];
while(kx-- > 0)pt++;
pt->rgbtBlue=pt1->rgbtBlue;
pt->rgbtGreen=pt1->rgbtGreen;
pt->rgbtRed=pt1->rgbtRed;
}
}
}
return temp;
}
//-----------------------------------------------------------------------
정성균 님이 쓰신 글 :
: 안녕하세요... Image를 사용해서 해당 이미지를 회전시키고 싶습니다..
: 음...~ 정확히 어떻게해야 할지 몰라서 이렇게 질문드립니다...
: 좋은정보좀..보내주십시요...
|