[英]Wpf partial image display
I need some tips for a little project. 我需要一些小项目的提示。 i am NOT trying to make a game of some sort, but i probably need some game-making techniques.
我不是要制作某种游戏,但我可能需要一些游戏制作技术。
I have to make a minimap viewer in wpf. 我必须在wpf中制作一个小地图查看器。
I have a set of map jpg files, but i only have to show a portion of them in a smaller rectangle that i draw on the app window. 我有一组地图jpg文件,但是我只需要在应用程序窗口上绘制的较小矩形中显示它们的一部分即可。
The goal is to make a minimap like in most games where you can only see a set portion of the whole map. 我们的目标是制作一个像大多数游戏一样的小地图,使您只能看到整个地图的一部分。
I am fairly new in the C# wpf environment so please be specific and if you give some code please explain what is not obvious. 我在C#wpf环境中还很陌生,因此请具体说明,如果您提供一些代码,请解释不明显的内容。
Thank you all. 谢谢你们。
If you have an Image
you can crop it like this: 如果您有
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.