组合图像以显示在图片框中

时间:2014-03-13 18:13:54

标签: c# 3d picturebox

在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

请帮助!

2 个答案:

答案 0 :(得分:1)

您可以使用GDI +歪斜图像a,b和c然后绘制新的" 3D"将图像转换为新的位图。

请阅读以下有关倾斜http://msdn.microsoft.com/en-us/library/3b575a03%28v=vs.110%29.aspx

的链接

当倾斜图像并将其绘制到新位图时,您必须确保以下内容:

  • a' s右上角= b左上角
  • a左下方= c左下方
  • b' s左下角= c左上角

现在这是基于图像是正方形的假设,我不确定你(作为开发人员)如何处理矩形图像(也许你可以拉伸它,由你决定)。我也使用相同的图像而不是A B和C,但概念应该相同。

这是一个用WinForm的OnPaint方法编写的快速示例

    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
        }
    }

答案 1 :(得分:0)

你必须做"透视变形"与图像。 查看类似问题的答案:4-point transform images

相关问题