共用方式為


如何:旋轉、反射和傾斜影像

您可以指定原始影像左上角、右上角和左下角的目的地點,來旋轉、反映和扭曲影像。 三個目的點會決定將原始矩形影像對應至平行投影的仿射轉換。

範例

例如,假設原始影像是左上角為 (0, 0), 右上角在 (100, 0), 左下角為 (0, 50) 的矩形。 現在假設您將這三個點對應至目的地點,如下所示。

原始點 目的地點
左上方 (0, 0) (200, 20)
右上方 (100, 0) (110, 100)
左下角 (0, 50) (250, 30)

下圖顯示原始影像和對應至平行投影的影像。 原始影像已扭曲、反映、旋轉和翻譯。 沿著原始影像上邊緣的 X 軸會對應到執行到 (200, 20) 和 (110, 100) 的線條。 沿著原始影像左邊緣的 Y 軸會對應至穿過 (200, 20, 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 Forms 使用而設計,而且需要 PaintEventArgs e,這是事件處理程式的參數 Paint 。 請務必將 取代 Stripes.bmp 為您系統上有效映像的路徑。

另請參閱