(解説は記事の方を御覧ください)
short rotateImage( FSSpec *fsc,short dir ) { Fixed fd,cx,cy,dx,dy; short ret=1; Rect wrt,drt; WindowClass wcls; WindowAttributes watt; WindowPtr wptr; CGrafPtr cptr; long rot; MatrixRecord mm; GraphicsImportComponent gi; GetPort( &cptr ); if( GetGraphicsImporterForFile( fsc,&gi ) ) return( -1 ); if( ! GraphicsImportGetNaturalBounds( gi,&drt ) ) { OffsetRect( &drt,-drt.left,-drt.top ); if( dir==0 || dir==2 ) wrt=drt; else SetRect( &wrt,0,0,drt.bottom,drt.right ); OffsetRect( &wrt,10,50 ); wcls=kDocumentWindowClass; watt=kWindowCloseBoxAttribute; if( ! ( ret=CreateNewWindow( wcls,watt,&wrt,&wptr ) ) ) { TransitionWindow( wptr,kWindowZoomTransitionEffect,kWindowShowTransitionAction,NULL ); GraphicsImportSetGWorld( gi,GetWindowPort( wptr ),0L ); GraphicsImportSetBoundsRect( gi,&drt ); if( dir ) { GraphicsImportGetMatrix( gi,&mm ); if( dir==1 ) rot=90; else if( dir==-1 ) rot=-90; else rot=180; fd=Long2Fix( rot ); cx=Long2Fix( (long)drt.right>>1 ); cy=Long2Fix( (long)drt.bottom>>1 ); RotateMatrix( &mm,fd,cx,cy ); if( dir!=2 ) { dx=Long2Fix( (long)(drt.bottom-drt.right)>>1 ); dy=Long2Fix( (long)(drt.right-drt.bottom)>>1 ); TranslateMatrix( &mm,dx,dy ); } GraphicsImportSetMatrix( gi,&mm ); } GraphicsImportDraw( gi ); } CloseComponent( gi ); } SetPort( cptr ); return( ret ); }
[小池邦人/オッティモ] |