本文整理匯總了C#中SharpDX.Direct3D9.Texture.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# Texture.Dispose方法的具體用法?C# Texture.Dispose怎麽用?C# Texture.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpDX.Direct3D9.Texture
的用法示例。
在下文中一共展示了Texture.Dispose方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TakeScreenshot
internal static void TakeScreenshot(string name, BaseTexture target, MyEffectScreenshot.ScreenshotTechniqueEnum technique)
{
if (ScreenshotOnlyFinal && name != "FinalScreen")
return;
// Screenshot object survives only one DRAW after created. We delete it immediatelly. So if 'm_screenshot'
// is not null we know we have to take screenshot and set it to null.
if (MyGuiManager.GetScreenshot() != null)
{
if (target is Texture)
{
Texture renderTarget = target as Texture;
Texture rt = new Texture(m_device, renderTarget.GetLevelDescription(0).Width, renderTarget.GetLevelDescription(0).Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
MyMinerGame.SetRenderTarget(rt, null);
BlendState.NonPremultiplied.Apply();
MyEffectScreenshot ssEffect = GetEffect(MyEffects.Screenshot) as MyEffectScreenshot;
ssEffect.SetSourceTexture(renderTarget);
ssEffect.SetTechnique(technique);
MyGuiManager.GetFullscreenQuad().Draw(ssEffect);
MyMinerGame.SetRenderTarget(null, null);
MyGuiManager.GetScreenshot().SaveTexture2D(rt, name);
rt.Dispose();
}
else if (target is CubeTexture)
{
string filename = MyGuiManager.GetScreenshot().GetFilename(name + ".dds");
CubeTexture.ToFile(target, filename, ImageFileFormat.Dds);
//MyDDSFile.DDSToFile(filename, true, target, false);
}
}
}
示例2: TakeScreenshot
internal static void TakeScreenshot(string name, BaseTexture target, MyEffectScreenshot.ScreenshotTechniqueEnum technique)
{
if (ScreenshotOnlyFinal && name != "FinalScreen" && name != "test")
return;
// Screenshot object survives only one DRAW after created. We delete it immediatelly. So if 'm_screenshot'
// is not null we know we have to take screenshot and set it to null.
if (m_screenshot != null)
{
try
{
if (target is Texture)
{
Texture renderTarget = target as Texture;
Texture rt = new Texture(MyRender.GraphicsDevice, renderTarget.GetLevelDescription(0).Width, renderTarget.GetLevelDescription(0).Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
MyRender.SetRenderTarget(rt, null);
BlendState.NonPremultiplied.Apply();
DepthStencilState.None.Apply();
RasterizerState.CullNone.Apply();
MyEffectScreenshot ssEffect = GetEffect(MyEffects.Screenshot) as MyEffectScreenshot;
ssEffect.SetSourceTexture(renderTarget);
ssEffect.SetTechnique(technique);
ssEffect.SetScale(Vector2.One);
MyRender.GetFullscreenQuad().Draw(ssEffect);
MyRender.SetRenderTarget(null, null);
string filename = m_screenshot.SaveTexture2D(rt, name);
rt.Dispose();
MyRenderProxy.ScreenshotTaken(filename != null, filename, m_screenshot.ShowNotification);
}
else if (target is CubeTexture)
{
string filename = m_screenshot.GetFilename(name + ".dds");
CubeTexture.ToFile(target, filename, ImageFileFormat.Dds);
MyRenderProxy.ScreenshotTaken(true, filename, m_screenshot.ShowNotification);
}
}
catch (Exception e)
{
Log.WriteLine("Error while taking screenshot.");
Log.WriteLine(e.ToString());
MyRenderProxy.ScreenshotTaken(false, null, m_screenshot.ShowNotification);
}
}
}
示例3: SaveScreenshot
public static void SaveScreenshot(Texture texture2D, string file)
{
MyMwcLog.WriteLine("MyScreenshot.SaveTexture2D() - START");
MyMwcLog.IncreaseIndent();
Texture systemTex = new Texture(MinerWars.AppCode.App.MyMinerGame.Static.GraphicsDevice, texture2D.GetLevelDescription(0).Width, texture2D.GetLevelDescription(0).Height, 0, Usage.None, Format.A8R8G8B8, Pool.SystemMemory);
Surface sourceSurface = texture2D.GetSurfaceLevel(0);
Surface destSurface = systemTex.GetSurfaceLevel(0);
MinerWars.AppCode.App.MyMinerGame.Static.GraphicsDevice.GetRenderTargetData(sourceSurface, destSurface);
sourceSurface.Dispose();
destSurface.Dispose();
texture2D = systemTex;
try
{
MyMwcLog.WriteLine("File: " + file);
MyFileSystemUtils.CreateFolderForFile(file);
Stack<SharpDX.Rectangle> tiles = new Stack<SharpDX.Rectangle>();
int tileWidth = texture2D.GetLevelDescription(0).Width;
int tileHeight = texture2D.GetLevelDescription(0).Height;
while (tileWidth > 3200)
{
tileWidth /= 2;
tileHeight /= 2;
}
int widthOffset = 0;
int heightOffset = 0;
while (widthOffset < texture2D.GetLevelDescription(0).Width)
{
while (heightOffset < texture2D.GetLevelDescription(0).Height)
{
tiles.Push(new SharpDX.Rectangle(widthOffset, heightOffset, tileWidth, tileHeight));
heightOffset += tileHeight;
}
heightOffset = 0;
widthOffset += tileWidth;
}
int sc = 0;
while (tiles.Count > 0)
{
SharpDX.Rectangle rect = tiles.Pop();
byte[] data = new byte[rect.Width * rect.Height * 4];
SharpDX.Rectangle rect2 = new SharpDX.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
//texture2D.GetData<byte>(0, rect2, data, 0, data.Length);
DataStream ds;
texture2D.LockRectangle(0, rect2, LockFlags.None, out ds);
ds.Read(data, 0, data.Length);
/*
for (int i = 0; i < data.Length; i += 4)
{
//Swap ARGB <-> RGBA
byte b = data[i + 0];
byte g = data[i + 1];
byte r = data[i + 2];
byte a = data[i + 3];
data[i + 0] = r; //Blue
data[i + 1] = g; //Green
data[i + 2] = b; //Red
data[i + 3] = a; //Alpha
} */
ds.Seek(0, SeekOrigin.Begin);
ds.WriteRange(data);
texture2D.UnlockRectangle(0);
string filename = file.Replace(".png", "_" + sc.ToString("##00") + ".png");
using (Stream stream = File.Create(filename))
{
System.Drawing.Bitmap image = new System.Drawing.Bitmap(rect.Width, rect.Height);
System.Drawing.Imaging.BitmapData imageData = image.LockBits(new System.Drawing.Rectangle(0,0,rect.Width, rect.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Runtime.InteropServices.Marshal.Copy(data, 0, imageData.Scan0, data.Length);
image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
image.UnlockBits(imageData);
image.Dispose();
//texture2D.SaveAsPng(stream, texture2D.Width, texture2D.Height);
//BaseTexture.ToStream(texture2D, ImageFileFormat.Png);
}
sc++;
GC.Collect();
}
}
//.........這裏部分代碼省略.........