2 c# xna textures image-manipulation winforms
我正在为我在空闲时间设计的XNA游戏的地图编辑器工作.地图中使用的艺术品存储在单个纹理上,矩形存储有坐标和宽度等.
在winforms应用程序中,我可以通过从列表框中选择我想要的段来添加段,列表框是从可能段的数组中填充的.
问题是我希望能够显示所选片段的预览,因为它存储在一个共同的纹理上,我不能简单地设置一个图片框来显示图像.
无论如何使用矩形信息(.x,.y,.width,.height)只显示图片框中的图像部分,或者将部分blit到位图并显示?
非常感谢
迈克尔艾伦
您可能想要查看GDI库.一起使用Image或Bitmap对象和Graphics.DrawImage()将获得您正在寻找的东西.
private void DrawImageRectRect(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create rectangle for displaying image.
Rectangle destRect = new Rectangle(100, 100, 450, 150);
// Create rectangle for source image.
Rectangle srcRect = new Rectangle(50, 50, 150, 150);
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw image to screen.
e.Graphics.DrawImage(newImage, destRect, srcRect, units);
}
Run Code Online (Sandbox Code Playgroud)
您可能也有兴趣在WinForm中使用XNA而不是使用PictureBoxes和GDI.它还没有100%支持,但是可以在这里找到关于它的教程.
| 归档时间: |
|
| 查看次数: |
8197 次 |
| 最近记录: |