在C#Windows窗體中,我希望能夠操作圖像以將其顯示爲3個圖像放在一起。操作包括對於三個軸中的每一個,我在每個軸上都有一個2D圖像。結果看起來像一個3D圖像。組合圖像以顯示在圖片框中
例如,如果我有3個位圖圖像; a,b和c。然後,我想製作一個3D圖像,其中x軸將具有圖像a,y軸將具有圖像b,並且z軸將具有圖像c。
像這樣:http://chanceandchoice.files.wordpress.com/2008/11/planes.jpg
請幫助!
在C#Windows窗體中,我希望能夠操作圖像以將其顯示爲3個圖像放在一起。操作包括對於三個軸中的每一個,我在每個軸上都有一個2D圖像。結果看起來像一個3D圖像。組合圖像以顯示在圖片框中
例如,如果我有3個位圖圖像; a,b和c。然後,我想製作一個3D圖像,其中x軸將具有圖像a,y軸將具有圖像b,並且z軸將具有圖像c。
像這樣:http://chanceandchoice.files.wordpress.com/2008/11/planes.jpg
請幫助!
您可以使用GDI +傾斜圖像a,b和c,然後將新的「3D」圖像繪製到新的位圖中。
請仔細閱讀有關傾斜http://msdn.microsoft.com/en-us/library/3b575a03%28v=vs.110%29.aspx
當歪斜的圖像,並把他們拉入新的位圖下面的鏈接,你必須確保滿足以下條件:
現在這是基於假設圖像是正方形,我不知道你(作爲開發人員)如何處理矩形圖像(也許你可以伸展它,取決於你)。我也使用相同的圖像,而不是A B和C,但概念應該相同。
這是寫在一個WinForm
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Bitmap xImage = new Bitmap(@"PATH TO IMAGE");
Size xImageSize = xImage.Size;
int Skew = 30;
using (Bitmap xNewImage = new Bitmap(120, 120)) //Determine your size
{
using (Graphics xGraphics = Graphics.FromImage(xNewImage))
{
Point[] xPointsA =
{
new Point(0, Skew), //Upper Left
new Point(xImageSize.Width, 0), //Upper Right
new Point(0, xImageSize.Height + Skew) //Lower left
};
Point[] xPointsB =
{
new Point(xImageSize.Width, 0), //Upper Left
new Point(xImageSize.Width*2, Skew), //Upper Right
new Point(xImageSize.Width, xImageSize.Height) //Lower left
};
Point[] xPointsC =
{
new Point(xImageSize.Width, xImageSize.Height), //Upper Left
new Point(xImageSize.Width*2, xImageSize.Height + Skew), //Upper Right
new Point(0, xImageSize.Height + Skew) //Lower left
};
//Draw to new Image
xGraphics.DrawImage(xImage, xPointsA);
xGraphics.DrawImage(xImage, xPointsB);
xGraphics.DrawImage(xImage, xPointsC);
}
e.Graphics.DrawImage(xNewImage, new Point()); //Here you would want to assign the new image to the picture box
}
}
你必須對圖像進行「透視變形」。 看看類似問題的答案:4-point transform images
感謝的OnPaint方法一個簡單的例子!它非常完美! – Afifa