Wpf部分图像显示

时间:2015-07-27 07:05:37

标签: c# wpf image

我需要一些小项目的提示。 我不是想制作某种类型的游戏,但我可能需要一些游戏制作技术。

我必须在wpf中创建一个迷你地图查看器。

我有一组地图jpg文件,但我只需要在应用程序窗口中绘制的较小矩形中显示它们的一部分。

目标是在大多数游戏中制作小地图,只能看到整个地图的一部分。

我在C#wpf环境中相当新,所以请具体一点,如果你给出一些代码,请解释一下不明显的内容。

谢谢大家。

1 个答案:

答案 0 :(得分:0)

如果您有Image,可以像这样裁剪:

public static Bitmap CropImage(Image source, int x,int y,int width,int height)
{
    Rectangle crop = new Rectangle(x, y, width, height);

    var bmp = new Bitmap(crop.Width, crop.Height);
    using (var gr = Graphics.FromImage(bmp))
    {
        gr.DrawImage(source, new Rectangle(0, 0, bmp.Width, bmp.Height), crop, GraphicsUnit.Pixel);
    }
    return bmp;
} 
相关问题