元のイメージの左上、右上、左下の角に変換先ポイントを指定することで、イメージを回転、反射、傾斜させることができます。 3 つの変換先ポイントは、元の四角形の画像を平行四辺形にマップするアフィン変換を決定します。
例
たとえば、元の画像が左上隅が (0,0)、右上隅が (100,0)、左下隅が (0, 50) の四角形であるとします。 次に、これらの 3 つのポイントを次のように目的地にマップするとします。
元のポイント | 宛先ポイント |
---|---|
左上 (0,0) | (200, 20) |
右上 (100, 0) | (110, 100) |
左下 (0、50) | (250, 30) |
次の図は、元の画像と、並列四辺形にマップされたイメージを示しています。 元の画像は、傾斜、反射、回転、および変換されています。 元のイメージの上端に沿った x 軸は、(200,20) と (110, 100) を通る線にマップされます。 元のイメージの左端に沿った y 軸は、(200,20) と (250, 30) を通る線にマップされます。
次の図は、写真画像に適用される同様の変換を示しています。
次の図は、メタファイルに適用される同様の変換を示しています。
次の例では、最初の図に示す画像を生成します。
Point[] destinationPoints = {
new Point(200, 20), // destination for upper-left point of
// original
new Point(110, 100), // destination for upper-right point of
// original
new Point(250, 30)}; // destination for lower-left point of
// original
Image image = new Bitmap("Stripes.bmp");
// Draw the image unaltered with its upper-left corner at (0, 0).
e.Graphics.DrawImage(image, 0, 0);
// Draw the image mapped to the parallelogram.
e.Graphics.DrawImage(image, destinationPoints);
' New Point(200, 20) = destination for upper-left point of original
' New Point(110, 100) = destination for upper-right point of original
' New Point(250, 30) = destination for lower-left point of original
Dim destinationPoints As Point() = { _
New Point(200, 20), _
New Point(110, 100), _
New Point(250, 30)}
Dim image As New Bitmap("Stripes.bmp")
' Draw the image unaltered with its upper-left corner at (0, 0).
e.Graphics.DrawImage(image, 0, 0)
' Draw the image mapped to the parallelogram.
e.Graphics.DrawImage(image, destinationPoints)
コードのコンパイル
前の例は Windows フォームで使用できるように設計されており、PaintEventArgs イベント ハンドラーのパラメーターである e
Paintが必要です。
Stripes.bmp
は、システムで有効なイメージへのパスに置き換えてください。
こちらも参照ください
.NET Desktop feedback