Windows Phone XNA 용으로 개발 중이며 전체 이미지가 필요없는 경우 메모리 영향을 줄이기 위해 더 작은 크기의 텍스처를로드하려고합니다.XNA에서 텍스처 크기 조정을로드하십시오.
이public static Texture2D LoadResized(string texturePath, float scale)
{
Texture2D texLoaded = Content.Load<Texture2D>(texturePath);
Vector2 resizedSize = new Vector2(texLoaded.Width * scale, texLoaded.Height * scale);
Texture2D resized = ResizeTexture(texLoaded, resizedSize);
//texLoaded.Dispose();
return resized;
}
public static Texture2D ResizeTexture(Texture2D toResize, Vector2 targetSize)
{
RenderTarget2D renderTarget = new RenderTarget2D(
GraphicsDevice, (int)targetSize.X, (int)targetSize.Y);
Rectangle destinationRectangle = new Rectangle(
0, 0, (int)targetSize.X, (int)targetSize.Y);
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(Color.Transparent);
SpriteBatch.Begin();
SpriteBatch.Draw(toResize, destinationRectangle, Color.White);
SpriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
return renderTarget;
}
이 텍스처 크기가 조정됩니다 점에서 작동하지만 메모리 사용에서의 텍스처 "과 같습니다
나의 현재 솔루션은 그리 사용하는 작은 텍스처로 그 렌더 타겟을 반환하는 렌더 타겟을 사용하는 것입니다 texLoaded "는 해제되지 않습니다. 주석 처리되지 않은 Dispose 메서드를 사용하면 SpriteBatch.End()가 삭제 된 예외를 throw합니다.
메모리 사용량을 줄이기 위해 텍스처를로드하는 다른 방법은 있습니까?