本文整理汇总了C#中Texture2D.Unmap方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.Unmap方法的具体用法?C# Texture2D.Unmap怎么用?C# Texture2D.Unmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture2D
的用法示例。
在下文中一共展示了Texture2D.Unmap方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadBitmapInTexture
private void LoadBitmapInTexture(Bitmap bitmap, Texture2D texture)
{
var rect = texture.Map(0, MapMode.WriteDiscard, MapFlags.None);
if (rect.Data.CanWrite)
{
for (int j = 0; j < texture.Description.Height; j++)
{
int rowStart = j * rect.Pitch;
rect.Data.Seek(rowStart, SeekOrigin.Begin);
for (int i = 0; i < texture.Description.Width; i++)
{
var color = bitmap.GetPixel(i, j);
rect.Data.WriteByte((byte)color.R);
rect.Data.WriteByte((byte)color.G);
rect.Data.WriteByte((byte)color.B);
rect.Data.WriteByte((byte)color.A);
}
}
}
texture.Unmap(0);
}
示例2: Make3D
private static Texture2D Make3D(Texture2D stereoTexture)
{
NvStereoImageHeader header = new NvStereoImageHeader(0x4433564e, 3840, 1080, 4, 0x00000002);
// stereoTexture contains a stereo image with the left eye image on the left half
// and the right eye image on the right half
// this staging texture will have an extra row to contain the stereo signature
Texture2DDescription stagingDesc = new Texture2DDescription()
{
ArraySize = 1,
Width = 2*size.Width,
Height = size.Height + 1,
BindFlags = BindFlags.None,
CpuAccessFlags = CpuAccessFlags.Write,
Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Staging,
MipLevels = 1,
SampleDescription = new SampleDescription(1, 0)
};
Texture2D staging = new Texture2D(device, stagingDesc);
// Identify the source texture region to copy (all of it)
ResourceRegion stereoSrcBox = new ResourceRegion
{Front = 0, Back = 1, Top = 0, Bottom = size.Height, Left = 0, Right = 2*size.Width};
// Copy it to the staging texture
device.CopySubresourceRegion(stereoTexture, 0, stereoSrcBox, staging, 0, 0, 0, 0);
// Open the staging texture for reading
DataRectangle box = staging.Map(0, MapMode.Write, SlimDX.Direct3D10.MapFlags.None);
// Go to the last row
//box.Data.Seek(stereoTexture.Description.Width*stereoTexture.Description.Height*4, System.IO.SeekOrigin.Begin);
box.Data.Seek(box.Pitch*1080, System.IO.SeekOrigin.Begin);
// Write the NVSTEREO header
box.Data.Write(data, 0, data.Length);
staging.Unmap(0);
// Create the final stereoized texture
Texture2DDescription finalDesc = new Texture2DDescription()
{
ArraySize = 1,
Width = 2 * size.Width,
Height = size.Height + 1,
BindFlags = BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.Write,
Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Dynamic,
MipLevels = 1,
SampleDescription = new SampleDescription(1, 0)
};
// Copy the staging texture on a new texture to be used as a shader resource
Texture2D final = new Texture2D(device, finalDesc);
device.CopyResource(staging, final);
staging.Dispose();
return final;
}
示例3: ExtractRawBitmap
public byte[] ExtractRawBitmap()
{
// use a cpu bound resource
var textureDesc = new Texture2DDescription
{
MipLevels = 1,
ArraySize = 1,
BindFlags = BindFlags.None,
CpuAccessFlags = CpuAccessFlags.Read,
Format = Format.B8G8R8A8_UNorm,
OptionFlags = ResourceOptionFlags.None,
Width = _width,
Height = _height,
Usage = ResourceUsage.Staging,
SampleDescription = new SampleDescription(1, 0)
};
using (var cpuTexture = new Texture2D(_device, textureDesc))
{
#if NETFX_CORE
_device.ImmediateContext.CopyResource(_texture, cpuTexture);
#else
_device.CopyResource(_texture, cpuTexture);
#endif
var bytesPerLine = _width * 4;
var res = new byte[bytesPerLine * _height];
#if NETFX_CORE
var data = _device.ImmediateContext.MapSubresource(cpuTexture, 0, MapMode.Read, MapFlags.None);
#else
var data = cpuTexture.Map(0, MapMode.Read, MapFlags.None);
#endif
try
{
IntPtr sourcePtr = data.DataPointer;
int targetOffset = 0;
for (int i = 0; i != _height; ++i)
{
Marshal.Copy(sourcePtr, res, targetOffset, bytesPerLine);
#if NETFX_CORE
sourcePtr += data.RowPitch;
#else
sourcePtr += data.Pitch;
#endif
targetOffset += bytesPerLine;
}
return res;
}
finally
{
#if NETFX_CORE
_device.ImmediateContext.UnmapSubresource(cpuTexture, 0);
#else
cpuTexture.Unmap(0);
#endif
}
}
}