小编kem*_*t90的帖子

使用RenderTarget2D从Stream加载Texture2D,在游戏窗口最小化后纹理消失

我从目录加载纹理有一些问题.也许代码优先:

private Texture2D LoadTextureStream(string filePath)
{
    Texture2D file = null;
    RenderTarget2D result = null;

    try
    {
        using (System.IO.Stream titleStream = TitleContainer.OpenStream(filePath))
        {
            file = Texture2D.FromStream(GraphicsDevice, titleStream);
        }
    }
    catch
    {
        throw new System.IO.FileLoadException("Cannot load '" + filePath + "' file!");
    }
    PresentationParameters pp = GraphicsDevice.PresentationParameters;
    //Setup a render target to hold our final texture which will have premulitplied alpha values
    result = new RenderTarget2D(GraphicsDevice, file.Width, file.Height, true, pp.BackBufferFormat, pp.DepthStencilFormat);

    GraphicsDevice.SetRenderTarget(result);
    GraphicsDevice.Clear(Color.Black);

    //Multiply each color by the source alpha, and write …
Run Code Online (Sandbox Code Playgroud)

c# xna-4.0

1
推荐指数
1
解决办法
2154
查看次数

标签 统计

c# ×1

xna-4.0 ×1