XNA - 用现有纹理填充多边形? [英] XNA - Fill polygon with existing texture?
本文介绍了XNA - 用现有纹理填充多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hey Codeproject,
如果我的多边形类似于带有铜线的正方形:
0:0,0
1:0,32
2:32,32
3:32,0
如何用现有的Texture2D填充那些cooardinates(方形),并将带纹理的多边形转换为另一个Texture2D?
这就是我的意思:
Texture2D:---
多边形:[]
新的Texture2D:[ - ]
Hey Codeproject,
If I have a polygon that resembles a square with the cooardinates:
0: 0, 0
1: 0, 32
2: 32, 32
3: 32, 0
How would I fill those cooardinates(The square) with an existing Texture2D, and convert the polygon with the texture to another Texture2D?
Here's what I mean:
Texture2D: ---
Polygon: [ ]
New Texture2D: [-]
推荐答案
我已经谷歌搜索了一段时间,我遇到了这个。我将对此进行测试。
I've been Googling for a while, and I came across this. I'll be testing this out.
private Bitmap ClippedBitmap(Bitmap texture, Point[] pointsArray, out Point position)
{
int minX = pointsArray.Min(x => x.X);
int maxX = pointsArray.Max(x => x.X);
int minY = pointsArray.Min(x => x.Y);
int maxY = pointsArray.Max(x => x.Y);
position = new Point(minX, minY);
Bitmap bit = new Bitmap(maxX - minX, maxY - minY);
Point[] offset = new Point[pointsArray.Length];
pointsArray.CopyTo(offset, 0);
offset = Array.ConvertAll(offset, x=> x = new Point(x.X - minX,x.Y - minY));
Graphics g = Graphics.FromImage(bit);
TextureBrush tb = new TextureBrush(texture);
g.FillPolygon(tb, offset);
return bit;
}
这篇关于XNA - 用现有纹理填充多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文