C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[48569] Re:이미지 회전하는 방법??
장성호 [nasilso] 2006 읽음    2007-03-26 12:32
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를 사용해서 해당 이미지를 회전시키고 싶습니다..
: 음...~ 정확히 어떻게해야 할지 몰라서 이렇게 질문드립니다...
: 좋은정보좀..보내주십시요...

+ -

관련 글 리스트
48559 이미지 회전하는 방법?? 정성균 1190 2007/03/24
48569     Re:이미지 회전하는 방법?? 장성호 2006 2007/03/26
48563     Re:이미지 회전하는 방법?? 박지훈.임프 1434 2007/03/26
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.