高度な検索
Developer Connection
Member Login ログイン | ご入会 ADC連絡先

Technical Q&A QA1144
GraphicsImportSetBoundsRect resets your Matrix


Q: 自分のアプリケーションで画像を回転させるためにグラフィックスインポータを使おうとしています。描画レクタングルを設定するために、GraphicsImportSetMatrix を呼び出し、その後 GraphicsImportSetBoundsRect を呼び出していますが、GraphicsImportDraw を呼び出しても画像が回転していません。何が間違っているのでしょうか?

A: GraphicsImportSetBoundsRect は、画像の元の境界を、指定された境界に対応させるための変換行列を作成した後、その行列を設定します。このため、GraphicsImportSetMatrix への最初の呼び出しによって設定された行列がリセットされます。必要なのは、GraphicsImportSetMatrix を 1 度呼び出すことだけです。


リスト 1 は、時計回りに 90 度回転させるコードを示します。

OSErr Rotate90(GraphicsImporterComponent inImporter)
{
    Rect theNaturalBounds;
    MatrixRecord theMatrix;
    OSErr err;

    err = GraphicsImportGetNaturalBounds(inImporter, &theNaturalBounds);
    if (err) goto bail;

    // 「原点を中心に回転しその後変換する方が
    // どこが回転の中心として適切かを見つけ出すよりもはるかに簡単」とブルーはいう 
    SetIdentityMatrix(&theMatrix);
    RotateMatrix(&theMatrix, Long2Fix(90), 0, 0);
    TranslateMatrix(&theMatrix, Long2Fix(theNaturalBounds.bottom), 0);

    err = GraphicsImportSetMatrix(inImporter, &theMatrix);

bail:
    return err;
}

リスト 1 時計回りに 90 度の回転



リスト 2 は、回転に縮小拡大を追加するコードを示します。

OSErr RotateAndScale(GraphicsImporterComponent inImporter)
{
    Rect theNaturalBounds;
    MatrixRecord theMatrix;
    OSErr err;

    err = GraphicsImportGetNaturalBounds(inImporter, &theNaturalBounds);
    if (err) goto bail;

    SetIdentityMatrix(&theMatrix);
    RotateMatrix(&theMatrix, Long2Fix(90), 0, 0);
    TranslateMatrix(&theMatrix, Long2Fix(theNaturalBounds.bottom), 0);

    // 50 % 縮小
    ScaleMatrix(&theMatrix, fixed1 / 2, fixed1 / 2, 0, 0);

    err = GraphicsImportSetMatrix(inImporter, &theMatrix);

bail:
    return err;
}

リスト 2 時計回りに 90 度の回転と 50 % の縮小


 


[2002 年 5 月 25 日]