我需要在 texture2d 中渲染一个精灵,以便以后可以在屏幕上渲染这个纹理,但同时我需要访问这个修改过的纹理的像素,所以,如果我添加让我们说纹理中的一个精灵,我在精灵所在的坐标中调用获取像素函数,然后它应该给我对应于精灵的新像素值(已与纹理2d混合)。
我使用的是 xna 4.0 而不是 3.5 或更低。
谢谢。
相当于 GDI 中的 Graphics.FromImage(img).DrawImage(...
我试过这个但失败了
public static Texture2D DrawSomething(Texture2D old, int X, int Y, int radius) {
var pp = Res.game.GraphicsDevice.PresentationParameters;
var r = new RenderTarget2D(Res.game.GraphicsDevice, old.Width, old.Height, false, pp.BackBufferFormat, pp.DepthStencilFormat,
pp.MultiSampleCount, RenderTargetUsage.DiscardContents);
Res.game.GraphicsDevice.SetRenderTarget(r);
var s = new SpriteBatch(r.GraphicsDevice);
s.Begin();
s.Draw(old, new Vector2(0, 0), Color.White);
s.Draw(Res.picture, new Rectangle(X - radius / 2, Y - radius / 2, radius, radius), Color.White);
s.End();
Res.game.GraphicsDevice.SetRenderTarget(null);
return r;
}
Res.game 基本上是一个指向主要游戏形式的指针,而 Res.picture 是一个随机的 texture2d