2009-04-13 9 views
1

、私はそれが角度Nを回転させる必要がある、キャンバス上の特定の角度で画像を描画する必要があり、その中心がX上で、Ygdi +でキャンバスに画像を描画するサンプルがありますか?

 Matrix myPathMatrix; 
     myPathMatrix.Translate(x, y, MatrixOrderAppend); 
     myPathMatrix.Rotate(angle, MatrixOrderAppend); 
     canvas->SetTransform(&myPathMatrix); 
     Draw(canvas);// draw the image 
     myPathMatrix.Rotate(-angle, MatrixOrderAppend); 
     myPathMatrix.Translate(-x, -y, MatrixOrderAppend); 
     canvas->SetTransform(&myPathMatrix); 

しかし、私は、IMGの左上隅によって回転見つけます画像を中心に回転させる必要があります。 どうすればいいですか? 多くの感謝!

答えて

2

デフォルトで左上の回転「中心」を変更する必要があります。
ここで私はネットにあるいくつかのコード:

private Bitmap rotateImage(Bitmap b, float angle) 
{ 
    //create a new empty bitmap to hold rotated image 
    Bitmap returnBitmap = new Bitmap(b.Width, b.Height); 
    //make a graphics object from the empty bitmap 
    Graphics g = Graphics.FromImage(returnBitmap); 
    //move rotation point to center of image 
    g.TranslateTransform((float)b.Width/2, (float)b.Height/2); 
    //rotate 
    g.RotateTransform(angle); 
    //move image back 
    g.TranslateTransform(-(float)b.Width/2,-(float)b.Height/2); 
    //draw passed in image onto graphics object 
    g.DrawImage(b, new Point(0, 0)); 
    return returnBitmap; 
} 
+0

はどうもありがとうございました! – user25749

関連する問題