本文整理汇总了C#中DataStream类的典型用法代码示例。如果您正苦于以下问题:C# DataStream类的具体用法?C# DataStream怎么用?C# DataStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataStream类属于命名空间,在下文中一共展示了DataStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyTextureToBitmap
public static Image CopyTextureToBitmap(D3D.Texture2D texture)
{
int width = texture.Description.Width;
if (width % 16 != 0)
width = MathExtensions.Round(width, 16) + 16;
Bitmap bmp = new Bitmap(texture.Description.Width, texture.Description.Height, PixelFormat.Format32bppArgb);
BitmapData bData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
using (DataStream stream = new DataStream(bData.Scan0, bData.Stride * bData.Height, false, true))
{
DataRectangle rect = texture.Map(0, D3D.MapMode.Read, D3D.MapFlags.None);
using (DataStream texStream = rect.Data)
{
for (int y = 0; y < texture.Description.Height; y++)
for (int x = 0; x < rect.Pitch; x+=4)
{
byte[] bytes = texStream.ReadRange<byte>(4);
if (x < bmp.Width*4)
{
stream.Write<byte>(bytes[2]); // DXGI format is BGRA, GDI format is RGBA.
stream.Write<byte>(bytes[1]);
stream.Write<byte>(bytes[0]);
stream.Write<byte>(255);
}
}
}
}
bmp.UnlockBits(bData);
return bmp;
}
示例2: _GetRecordingStream
private DataStream _GetRecordingStream()
{
if (_recordingStream == null) {
_recordingStream = _sequence.SequenceData.DataStreams.CreateStream("Recording");
}
return _recordingStream;
}
示例3: MsfDirectory
/// <summary>
/// </summary>
/// <param name="reader">
/// </param>
/// <param name="head">
/// </param>
/// <param name="bits">
/// </param>
internal MsfDirectory(PdbReader reader, PdbFileHeader head, BitAccess bits)
{
bits.MinCapacity(head.directorySize);
var pages = reader.PagesFromSize(head.directorySize);
// 0..n in page of directory pages.
reader.Seek(head.directoryRoot, 0);
bits.FillBuffer(reader.reader, pages * 4);
var stream = new DataStream(head.directorySize, bits, pages);
bits.MinCapacity(head.directorySize);
stream.Read(reader, bits);
// 0..3 in directory pages
int count;
bits.ReadInt32(out count);
// 4..n
var sizes = new int[count];
bits.ReadInt32(sizes);
// n..m
this.streams = new DataStream[count];
for (var i = 0; i < count; i++)
{
if (sizes[i] <= 0)
{
this.streams[i] = new DataStream();
}
else
{
this.streams[i] = new DataStream(sizes[i], bits, reader.PagesFromSize(sizes[i]));
}
}
}
示例4: ToTexture3D
public ShaderResourceView ToTexture3D(Device graphicsDevice, Format format)
{
int sizeInBytes = sizeof(float) * width * height * depth;
DataStream stream = new DataStream(sizeInBytes, true, true);
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
for (int z = 0; z < depth; z++)
stream.Write(values[x, y, z]);
stream.Position = 0;
DataBox dataBox = new DataBox(sizeof(float) * width, sizeof(float) * width * height, stream);
Texture3DDescription description = new Texture3DDescription()
{
BindFlags = BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
Depth = depth,
Format = format,
Height = height,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default,
Width = width
};
Texture3D texture = new Texture3D(graphicsDevice, description, dataBox);
stream.Dispose();
return new ShaderResourceView(graphicsDevice, texture);
}
示例5: ObjRenderer
public ObjRenderer(Form1 F)
: base(F.Device)
{
P = F;
PortalRoomManager.Equals(null, null);
S = new Sorter();
string s0 = Environment.CurrentDirectory + "/resources/shaders/ambient_fast.fx";
SB_V = ShaderBytecode.CompileFromFile(s0, "VS_STATIC", "vs_4_0", ManagedSettings.ShaderCompileFlags, EffectFlags.None);
SB_P = ShaderBytecode.CompileFromFile(s0, "PS", "ps_4_0", ManagedSettings.ShaderCompileFlags, EffectFlags.None);
VS = new VertexShader(F.Device.HadrwareDevice(), SB_V);
PS = new PixelShader(F.Device.HadrwareDevice(), SB_P);
IL = new InputLayout(Device.HadrwareDevice(), SB_V, StaticVertex.ies);
BufferDescription desc = new BufferDescription
{
Usage = ResourceUsage.Default,
SizeInBytes = 2 * 64,
BindFlags = BindFlags.ConstantBuffer
};
cBuf = new SlimDX.Direct3D11.Buffer(Device.HadrwareDevice(), desc);
dS = new DataStream(2 * 64, true, true);
BufferDescription desc2 = new BufferDescription
{
Usage = ResourceUsage.Default,
SizeInBytes = 64,
BindFlags = BindFlags.ConstantBuffer
};
cBuf2 = new SlimDX.Direct3D11.Buffer(Device.HadrwareDevice(), desc2);
dS2 = new DataStream(64, true, true);
}
示例6: MeshContainer
public MeshContainer(Engine.Serialize.Mesh M)
{
if (M != null)
{
LocalAABBMax = M.AABBMax;
LocalAABBMin = M.AABBMin;
VertexsCount = M.VertexCount;
FaceCount = M.FaceCount;
BytesPerVertex = M.VertexData.Length / VertexsCount;
using (var vertices = new DataStream(BytesPerVertex * VertexsCount, true, true))
{
vertices.WriteRange<byte>(M.VertexData, 0, M.VertexData.Length);
vertices.Position = 0;
Vertexs = new Buffer(ModelViewer.Program.device, vertices, BytesPerVertex * VertexsCount, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0);
}
using (var indices = new DataStream(4 * FaceCount * 3, true, true))
{
indices.WriteRange<byte>(M.IndexData, 0, M.IndexData.Length);
indices.Position = 0;
Indices = new Buffer(ModelViewer.Program.device, indices, 4 * FaceCount * 3, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
}
}
}
示例7: SoundEffect
/// <summary>
/// Initializes a new instance of the <see cref="SoundEffect"/> class.
/// </summary>
/// <param name="audioManager">The associated audio manager instance.</param>
/// <param name="name">The name of the current instance.</param>
/// <param name="waveFormat">The format of the current instance.</param>
/// <param name="buffer">The buffer containing audio data.</param>
/// <param name="decodedPacketsInfo">The information regaring decoded packets.</param>
internal SoundEffect(AudioManager audioManager, string name, WaveFormat waveFormat, DataStream buffer, uint[] decodedPacketsInfo)
{
AudioManager = audioManager;
Name = name;
Format = waveFormat;
AudioBuffer = new AudioBuffer
{
Stream = buffer,
AudioBytes = (int)buffer.Length,
Flags = BufferFlags.EndOfStream,
};
LoopedAudioBuffer = new AudioBuffer
{
Stream = buffer,
AudioBytes = (int)buffer.Length,
Flags = BufferFlags.EndOfStream,
LoopCount = AudioBuffer.LoopInfinite,
};
DecodedPacketsInfo = decodedPacketsInfo;
Duration = Format.SampleRate > 0 ? TimeSpan.FromMilliseconds(GetSamplesDuration() * 1000 / Format.SampleRate) : TimeSpan.Zero;
children = new List<WeakReference>();
VoicePool = AudioManager.InstancePool.GetVoicePool(Format);
}
示例8: ResourceFontLoader
/// <summary>
/// Initializes a new instance of the <see cref="ResourceFontLoader"/> class.
/// </summary>
/// <param name="factory">The factory.</param>
public ResourceFontLoader(Factory factory)
{
_factory = factory;
foreach (var name in typeof(ResourceFontLoader).Assembly.GetManifestResourceNames())
{
if (name.EndsWith(".ttf"))
{
var fontBytes = Utilities.ReadStream(typeof (ResourceFontLoader).Assembly.GetManifestResourceStream(name));
var stream = new DataStream(fontBytes.Length, true, true);
stream.Write(fontBytes, 0, fontBytes.Length);
stream.Position = 0;
_fontStreams.Add(new ResourceFontFileStream(stream));
}
}
// Build a Key storage that stores the index of the font
_keyStream = new DataStream(sizeof(int) * _fontStreams.Count, true, true);
for (int i = 0; i < _fontStreams.Count; i++ )
_keyStream.Write((int)i);
_keyStream.Position = 0;
// Register the
_factory.RegisterFontFileLoader(this);
_factory.RegisterFontCollectionLoader(this);
}
示例9: IndexBuffer
public IndexBuffer(Device device, ushort[] indices)
{
if(device == null)
{
throw new ArgumentNullException("device");
}
if(indices == null)
{
throw new ArgumentNullException("indices");
}
using(var dataStream = new DataStream(sizeof(UInt16)*indices.Length, true, true))
{
dataStream.WriteRange(indices);
dataStream.Position = 0;
Buffer = new Buffer(device,
dataStream,
(int) dataStream.Length,
ResourceUsage.Immutable,
BindFlags.IndexBuffer,
CpuAccessFlags.None,
ResourceOptionFlags.None,
0);
}
Count = indices.Length;
}
示例10: BitmapImage
public BitmapImage(int width, int height, BitmapProperties properties)
{
mWidth = width;
mHeight = height;
mProperties = properties;
mData = new DataStream(width * height * 4, true, true);
}
示例11: DataStreams
//private DataNodeCollection _executingData;
public DataStreams()
{
// The sequence will have at least one stream to hold effect data.
_mainStream = new DataStream("Main");
_dataStreams.Add(_mainStream);
//_executingData = new DataNodeCollection();
}
示例12: MyGrassPatch
public MyGrassPatch(HeightMap heightMap, int size)
{
MyGrassPatch.width = size;
MyGrassPatch.length = size;
this.heightMap = heightMap;
System.Random rSeed = new Random();
//triangleCount = length * width * bladeBySquare * bladeBySquare * nbSegment * 2 * 4 * 2;
triangleCount = length * width * bladeBySquare * bladeBySquare * nbSegment * 4;
vertices = new DataStream((12+8) * triangleCount * 3, true, true);
for (int i = 0; i < width;i++)
for (int j = 0; j < length; j++)
{
for (int xb = 0;xb < bladeBySquare;xb++)
for (int yb = 0; yb < bladeBySquare; yb++)
{
float x = i + xb * 1f / bladeBySquare + ((float)rSeed.NextDouble()-0.5f) * 0.2f;
float z = j + yb * 1f / bladeBySquare + ((float)rSeed.NextDouble() - 0.5f) * 0.2f;
//float x = i + xb * 1f / bladeBySquare;
//float z = j + yb * 1f / bladeBySquare;
addBlade(x, heightMap.getHeight(x, z), z, 1.0f + (float)rSeed.NextDouble() * 0.2f, (float)(rSeed.NextDouble()*Math.PI));
}
}
vertices.Position = 0;
}
示例13: MyTerrain
public MyTerrain(HeightMap heightMap,int size)
{
MyTerrain.width = size;
MyTerrain.length = size;
this.heightMap = heightMap;
vertices = new DataStream((12+8) * triangleCount * 3, true, true);
for (int i = 0; i < width;i++)
for (int j = 0; j < length; j++)
{
float height;
height = heightMap.getHeight((float)i, (float)j);
vertices.Write(new Vector3(0.0f + i, height, 0.0f + j));
vertices.Write(new Vector2(0.0f, 0.0f));
height = heightMap.getHeight((float)i, (float)j+1f);
vertices.Write(new Vector3(0.0f + i, height, 1.0f + j));
vertices.Write(new Vector2(0.0f, 0.0f));
height = heightMap.getHeight((float)i+1, (float)j);
vertices.Write(new Vector3(1.0f + i, height, 0.0f + j));
vertices.Write(new Vector2(0.0f, 0.0f));
height = heightMap.getHeight((float)i, (float)j + 1);
vertices.Write(new Vector3(0.0f + i, height, 1.0f + j));
vertices.Write(new Vector2(0.0f, 0.0f));
height = heightMap.getHeight((float)i + 1, (float)j + 1);
vertices.Write(new Vector3(1.0f + i, height, 1.0f + j));
vertices.Write(new Vector2(0.0f, 0.0f));
height = heightMap.getHeight((float)i + 1, (float)j);
vertices.Write(new Vector3(1.0f + i, height, 0.0f + j));
vertices.Write(new Vector2(0.0f, 0.0f));
}
vertices.Position = 0;
}
示例14: CreateTexture2DFromBitmap
/// <summary>
/// Creates a <see cref="SharpDX.Direct3D11.Texture2D"/> from a WIC <see cref="SharpDX.WIC.BitmapSource"/>
/// </summary>
/// <param name="device">The Direct3D11 device</param>
/// <param name="bitmapSource">The WIC bitmap source</param>
/// <returns>A Texture2D</returns>
public static Texture2D CreateTexture2DFromBitmap(Device device, BitmapSource bitmapSource)
{
// Allocate DataStream to receive the WIC image pixels
int stride = bitmapSource.Size.Width * 4;
using (var buffer = new DataStream(bitmapSource.Size.Height * stride, true, true))
{
// Copy the content of the WIC to the buffer
Rectangle rect = new Rectangle();
var methods = bitmapSource.GetType().GetMethods();
bitmapSource.GetType().GetMethods().First(item => item.Name == "CopyPixels").Invoke(bitmapSource, new object[] { stride, buffer });
// bitmapSource.CopyPixels(stride, buffer);
return new Texture2D(device, new Texture2DDescription()
{
Width = bitmapSource.Size.Width,
Height = bitmapSource.Size.Height,
ArraySize = 1,
BindFlags = BindFlags.ShaderResource,
Usage = ResourceUsage.Immutable,
CpuAccessFlags =CpuAccessFlags.None,
Format = Format.R8G8B8A8_UNorm,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SampleDescription(1, 0),
}, new DataRectangle(buffer.DataPointer, stride));
}
}
示例15: GetAuthServerList
/// <summary>
/// Gets an auth server list for a specific username.
/// </summary>
/// <param name="userName">The username.</param>
/// <returns>A list of servers on success; otherwise, <c>null</c>.</returns>
public IPEndPoint[] GetAuthServerList( string userName )
{
userName = userName.ToLower();
byte[] userHash = CryptoHelper.JenkinsHash( Encoding.ASCII.GetBytes( userName ) );
uint userData = BitConverter.ToUInt32( userHash, 0 ) & 1;
TcpPacket packet = base.GetRawServerList( ESteam2ServerType.ProxyASClientAuthentication, NetHelpers.EndianSwap( userData ) );
if ( packet == null )
return null;
DataStream ds = new DataStream( packet.GetPayload(), true );
ushort numAddrs = ds.ReadUInt16();
IPEndPoint[] serverList = new IPEndPoint[ numAddrs ];
for ( int x = 0 ; x < numAddrs ; ++x )
{
IPAddrPort ipAddr = IPAddrPort.Deserialize( ds.ReadBytes( 6 ) );
serverList[ x ] = ipAddr;
}
return serverList;
}