本文整理汇总了C#中DataStream.Read方法的典型用法代码示例。如果您正苦于以下问题:C# DataStream.Read方法的具体用法?C# DataStream.Read怎么用?C# DataStream.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataStream
的用法示例。
在下文中一共展示了DataStream.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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]));
}
}
}
示例2: GetSample
public byte[] GetSample( AudioInfo audioInfo, TimeSpan? timeSpan )
{
SampleStruct samples = audioInfo.Samples as SampleStruct;
if ( timeSpan != null )
samples.DataPointers = samples.AudioDecoder.GetSamples ( timeSpan.Value ).GetEnumerator ();
if ( !samples.DataPointers.MoveNext () ) return null;
DataPointer data = samples.DataPointers.Current;
DataStream stream = new DataStream ( data.Pointer, data.Size, true, false );
byte [] buffer = new byte [ stream.Length ];
stream.Read ( buffer, 0, ( int ) stream.Length );
return buffer;
}
示例3: MsfDirectory
internal MsfDirectory(PdbReader reader, PdbFileHeader head, BitAccess bits)
{
int pages = reader.PagesFromSize(head.directorySize);
// 0..n in page of directory pages.
bits.MinCapacity(head.directorySize);
int directoryRootPages = head.directoryRoot.Length;
int pagesPerPage = head.pageSize / 4;
int pagesToGo = pages;
for (int i = 0; i < directoryRootPages; i++) {
int pagesInThisPage = pagesToGo <= pagesPerPage ? pagesToGo : pagesPerPage;
reader.Seek(head.directoryRoot[i], 0);
bits.Append(reader.reader, pagesInThisPage * 4);
pagesToGo -= pagesInThisPage;
}
bits.Position = 0;
DataStream 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
int[] sizes = new int[count];
bits.ReadInt32(sizes);
// n..m
streams = new DataStream[count];
for (int i = 0; i < count; i++) {
if (sizes[i] <= 0) {
streams[i] = new DataStream();
} else {
streams[i] = new DataStream(sizes[i], bits,
reader.PagesFromSize(sizes[i]));
}
}
}
示例4: GetBitmap
public static unsafe WriteableBitmap GetBitmap(this SharpDX.Direct3D11.Texture2D tex)
{
DataRectangle db;
DataStream data = new DataStream(tex.Description.Height * tex.Description.Width * 4, true, true);
using(var copy = tex.GetCopy())
using (var surface = copy.QueryInterface<SharpDX.DXGI.Surface>())
{
db = surface.Map(SharpDX.DXGI.MapFlags.Read, out data);
// can't destroy the surface now with WARP driver
int w = tex.Description.Width;
int h = tex.Description.Height;
var wb = new WriteableBitmap(w, h, 96.0, 96.0, PixelFormats.Bgra32, null);
wb.Lock();
try
{
uint* wbb = (uint*)wb.BackBuffer;
data.Position = 0;
for (int y = 0; y < h; y++)
{
data.Position = y * db.Pitch;
for (int x = 0; x < w; x++)
{
var c = data.Read<uint>();
wbb[y * w + x] = c;
}
}
}
finally
{
wb.AddDirtyRect(new Int32Rect(0, 0, w, h));
wb.Unlock();
data.Dispose();
}
return wb;
}
}
示例5: avcs
Color avcs(DataStream gs, Collection<long> positions)
{
byte[] bu = new byte[4];
int r = 0;
int g = 0;
int b = 0;
int i = 0;
foreach (long pos in positions)
{
gs.Position = pos;
gs.Read(bu, 0, 4);
r += bu[2];
g += bu[1];
b += bu[0];
i++;
}
return Color.FromArgb(r / i, g / i, b / i);
}
示例6: ShaderSignature
/// <summary>
/// Initializes a new instance of the <see cref="T:SharpDX.D3DCompiler.ShaderSignature"/> class.
/// </summary>
/// <param name="data">The data.</param>
public ShaderSignature(DataStream data)
{
Data = new byte[data.Length];
data.Read(Data, 0, Data.Length);
}
示例7: Load
public void Load()
{
byte[] effectBuffer = null;
ShaderSignature inputSignature;
try
{
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OpenSAGE.Shaders.Compiled.Simple.fxo"))
{
effectBuffer = new byte[stream.Length];
stream.Read(effectBuffer, 0, effectBuffer.Length);
}
using (DataStream stream = new DataStream(effectBuffer, true, true))
{
using (ShaderBytecode byteCode = new ShaderBytecode(stream))
{
_effect = new Effect(_device, byteCode);
}
}
}
catch
{
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OpenSAGE.Shaders.Simple.fx"))
{
effectBuffer = new byte[stream.Length];
stream.Read(effectBuffer, 0, effectBuffer.Length);
}
using (ShaderBytecode byteCode = ShaderBytecode.Compile(effectBuffer, "fx_5_0"))
{
_effect = new Effect(_device, byteCode);
}
}
_defaultTechnique = _effect.GetTechniqueByName("Default");
EffectPass pass = _defaultTechnique.GetPassByIndex(0);
inputSignature = pass.Description.Signature;
byte[] vertices = new byte[0x70];
int position = 0;
BufferWriter.WriteVector3(vertices, ref position, new Math.Vector3(0.0f, 0.5f, 0.5f));
BufferWriter.WriteLinearColorRGBA(vertices, ref position, new Math.LinearColor(1.0f, 0.0f, 0.0f));
BufferWriter.WriteVector3(vertices, ref position, new Math.Vector3(0.5f, -0.5f, 0.5f));
BufferWriter.WriteLinearColorRGBA(vertices, ref position, new Math.LinearColor(0.0f, 1.0f, 0.0f));
BufferWriter.WriteVector3(vertices, ref position, new Math.Vector3(-0.5f, -0.5f, 0.5f));
BufferWriter.WriteLinearColorRGBA(vertices, ref position, new Math.LinearColor(0.0f, 0.0f, 1.0f));
BufferWriter.WriteVector3(vertices, ref position, new Math.Vector3(-0.5f, 0.5f, 0.5f));
BufferWriter.WriteLinearColorRGBA(vertices, position, new Math.LinearColor(1.0f, 1.0f, 1.0f, 0.0f));
DataStream vertexStream = new DataStream(vertices, true, true);
_vertexBuffer = new D3D11Buffer(_device, vertexStream, 0x70,
ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
byte[] indices = new byte[12];
position = 0;
BufferWriter.WriteUInt16(indices, ref position, 0);
BufferWriter.WriteUInt16(indices, ref position, 1);
BufferWriter.WriteUInt16(indices, ref position, 2);
BufferWriter.WriteUInt16(indices, ref position, 3);
BufferWriter.WriteUInt16(indices, ref position, 0);
BufferWriter.WriteUInt16(indices, ref position, 2);
DataStream indexStream = new DataStream(indices, true, true);
_indexBuffer = new D3D11Buffer(_device, indexStream, 12,
ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
InputElement[] inElements = new[]
{
new InputElement("POSITION", 0, Format.R32G32B32_Float, 0),
new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 12, 0)
};
_inLayout = new InputLayout(_device, inputSignature, inElements);
_deviceContext.InputAssembler.InputLayout = _inLayout;
_deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
_deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vertexBuffer, 28, 0));
_deviceContext.InputAssembler.SetIndexBuffer(_indexBuffer, Format.R16_UInt, 0);
_defaultTechnique.GetPassByIndex(0).Apply(_deviceContext);
}
示例8: ShaderBytecode
/// <summary>
/// Initializes a new instance of the <see cref = "T:SharpDX.D3DCompiler.ShaderBytecode" /> class.
/// </summary>
/// <param name = "data">A <see cref = "T:SharpDX.DataStream" /> containing the compiled bytecode.</param>
public ShaderBytecode(DataStream data)
{
Data = new byte[data.Length];
data.Read(Data, 0, Data.Length);
}
示例9: LoadTKTX
/// <summary>
/// Saves the specified pixel buffers in TKTX format.
/// </summary>
internal static Image LoadTKTX(IntPtr dataPointer, int dataSize, bool makeACopy, GCHandle? handle)
{
// Make a copy?
if (makeACopy)
{
var temp = Utilities.AllocateMemory(dataSize);
Utilities.CopyMemory(temp, dataPointer, dataSize);
dataPointer = temp;
}
// Use DataStream to load from memory pointer
var imageStream = new DataStream(dataPointer, dataSize, true, true);
var beginPosition = imageStream.Position;
var serializer = new BinarySerializer(imageStream, SerializerMode.Read);
var description = default(ImageDescription);
// Load MagicCode TKTX
try
{
serializer.BeginChunk(MagicCodeTKTX);
} catch (InvalidChunkException ex)
{
// If magic code not found, return null
if (ex.ExpectedChunkId == MagicCodeTKTX)
return null;
throw;
}
// Read description
serializer.Serialize(ref description);
// Read size of pixel buffer
int size = 0;
serializer.Serialize(ref size);
// Pad to align pixel buffer on 16 bytes (fixed offset at 48 bytes from the beginning of the file).
var padBuffer = new byte[OffsetBufferTKTX - (int)(imageStream.Position - beginPosition)];
if (padBuffer.Length > 0)
{
if (imageStream.Read(padBuffer, 0, padBuffer.Length) != padBuffer.Length)
throw new EndOfStreamException();
}
// Check that current offset is exactly our fixed offset.
int pixelBufferOffsets = (int)serializer.Stream.Position;
if (pixelBufferOffsets != OffsetBufferTKTX)
throw new InvalidOperationException(string.Format("Unexpected offset [{0}] for pixel buffers. Must be {1}", pixelBufferOffsets, OffsetBufferTKTX));
// Seek to the end of the stream to the number of pixel buffers
imageStream.Seek(size, SeekOrigin.Current);
// Close the chunk to verify that we did read the whole chunk
serializer.EndChunk();
return new Image(description, dataPointer, pixelBufferOffsets, handle, makeACopy);
}
示例10: GetVectors
/// <summary>
/// Gets an array of <see cref="Vector3"/> from a <see cref="DataStream"/>.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="vertexCount">The vertex count.</param>
/// <param name="stride">The stride.</param>
/// <returns>An array of <see cref="Vector3"/> </returns>
public static Vector3[] GetVectors(DataStream stream, int vertexCount, int stride)
{
unsafe
{
var results = new Vector3[vertexCount];
for (int i = 0; i < vertexCount; i++)
{
results[i] = stream.Read<Vector3>();
stream.Position += stride - sizeof(Vector3);
}
return results;
}
}
示例11: CalculateAverageColor
Color CalculateAverageColor(DataStream gs)
{
int nBytes = Screen.PrimaryScreen.Bounds.Width * Screen.PrimaryScreen.Bounds.Height * 4;
byte[] bu = new byte[nBytes];
int r = 0;
int g = 0;
int b = 0;
int i = 0;
gs.Position = 0;
gs.Read(bu, 0, nBytes);
while (i < nBytes)
{
// Note: pixel format is BGR
b += bu[i];
g += bu[i + 1];
r += bu[i + 2];
i += 4;
}
int nPixels = i / 4;
return Color.FromArgb(r / nPixels, g / nPixels, b / nPixels);
}
示例12:
/// <summary>
/// Creates a font file stream object that encapsulates an open file resource.
/// </summary>
/// <param name="fontFileReferenceKey">A reference to a font file reference key that uniquely identifies the font file resource within the scope of the font loader being used. The buffer allocated for this key must at least be the size, in bytes, specified by fontFileReferenceKeySize.</param>
/// <returns>
/// a reference to the newly created <see cref="SharpDX.DirectWrite.FontFileStream"/> object.
/// </returns>
/// <remarks>
/// The resource is closed when the last reference to fontFileStream is released.
/// </remarks>
/// <unmanaged>HRESULT IDWriteFontFileLoader::CreateStreamFromKey([In, Buffer] const void* fontFileReferenceKey,[None] int fontFileReferenceKeySize,[Out] IDWriteFontFileStream** fontFileStream)</unmanaged>
FontFileStream FontFileLoader.CreateStreamFromKey(DataStream fontFileReferenceKey)
{
var index = fontFileReferenceKey.Read<int>();
return _fontStreams[index];
}
示例13: setOffset
private void setOffset(DataStream gs)
{
PixelColor[,] test = BitmapSourceHelper.GetPixels(new BitmapImage(new Uri(@"pack://application:,,,/MinesweeperSolver;component/Images/test.png")));
int testWidth = 5;
int testHeight = 5;
byte[] buffer = new byte[testWidth * 4 * testHeight];
PixelColor[,] pixels = new PixelColor[testWidth, testHeight];
for (int x = 0; x < screenWidth-5; x+=5)
{
for (int y = 0; y < screenHeight-5; y+=5)
{
for (int line = 0; line < testHeight; line++)
{
gs.Position = (line + y) * screenWidth * 4 + x * 4;
gs.Read(buffer, testWidth * 4 * line, testWidth * 4);
}
for (int a = 0; a < testWidth; a++)
{
for (int b = 0; b < testHeight; b++)
{
int offset = b * testWidth * 4 + (a * 4);
pixels[b, a].Red = buffer[offset + 2];
pixels[b, a].Green = buffer[offset + 1];
pixels[b, a].Blue = buffer[offset + 0];
}
}
if (BlockParser.CompareImages(pixels, test))
{
int finalX;
int finalY;
byte[] pixel = new byte[4];
for (finalX = x; finalX > 0; finalX--)
{
gs.Position = y * screenWidth * 4 + finalX * 4;
gs.Read(pixel, 0, 4);
if (compareInt(pixel[0], 58, 9) &&
compareInt(pixel[1], 52, 9) &&
compareInt(pixel[2], 47, 9))
break;
}
for (finalY = y; finalY > 0; finalY--)
{
gs.Position = finalY * screenWidth * 4 + x * 4;
gs.Read(pixel, 0, 4);
if (compareInt(pixel[0], 58, 9) &&
compareInt(pixel[1], 52, 9) &&
compareInt(pixel[2], 47, 9))
break;
}
xoffset = finalX-3;
yoffset = finalY-1;
return;
}
}
}
}
示例14: RenderToWriteableBitmap
public async Task<WriteableBitmap> RenderToWriteableBitmap(FrameworkElement fe)
{
var width = (int)Math.Ceiling(fe.ActualWidth);
var height = (int)Math.Ceiling(fe.ActualHeight);
if (width == 0 ||
height == 0)
{
throw new InvalidOperationException("Can't render an empty element. ActualWidth or ActualHeight equal 0. Consider awaiting a WaitForNonZeroSizeAsync() call or invoking Measure()/Arrange() before the call to Render().");
}
using (var renderTargetBitmap = CreateRenderTargetBitmap(width, height))
{
_d2DDeviceContext.Target = renderTargetBitmap;
_d2DDeviceContext.AntialiasMode = D2D.AntialiasMode.PerPrimitive;
_d2DDeviceContext.TextAntialiasMode = D2D.TextAntialiasMode.Grayscale;
await Compose(_d2DDeviceContext, fe);
using (var cpuReadBitmap = CreateCpuReadBitmap(width, height))
{
cpuReadBitmap.CopyFromRenderTarget(
_d2DDeviceContext,
new Point(0, 0),
new SharpDX.Rectangle(0, 0, width, height));
var mappedRect = cpuReadBitmap.Map(D2D.MapOptions.Read);
try
{
using (var readStream =
new DataStream(
userBuffer: mappedRect.DataPointer,
sizeInBytes: mappedRect.Pitch * height,
canRead: true,
canWrite: false))
{
var wb = new WriteableBitmap(width, height);
using (var writeStream = wb.PixelBuffer.AsStream())
{
var buffer = new byte[mappedRect.Pitch];
for (int i = 0; i < height; i++)
{
readStream.Read(buffer, 0, mappedRect.Pitch);
writeStream.Write(buffer, 0, width * 4);
}
}
wb.Invalidate();
return wb;
}
}
finally
{
cpuReadBitmap.Unmap();
}
}
}
}
示例15: Update
public void Update(IPluginIO pin, DX11RenderContext context)
{
if (this.FInvalidate || !this.FOutGeom[0].Contains(context))
{
int vertexoffset = 0;
List<Pos3Norm3Tex2InstanceVertex> vertices = new List<Pos3Norm3Tex2InstanceVertex>();
List<int> indices = new List<int>();
List<Vector2> uvs = new List<Vector2>();
int cnt = this.FinUseName[0] ? idsort.Count : this.FInScene[0].MeshCount;
for (int i = 0; i < cnt; i++)
{
AssimpMesh assimpmesh = this.FinUseName[0] == false ? this.FInScene[0].Meshes[i] : this.FInScene[0].Meshes[idsort[i]];
List<int> inds = assimpmesh.Indices;
if (inds.Count > 0 && assimpmesh.VerticesCount > 0)
{
var texcd = assimpmesh.GetInputElements().Where( ie => ie.SemanticName == "TEXCOORD").FirstOrDefault();
bool zuv = false;
if (texcd != null)
{
zuv = texcd.Format == SlimDX.DXGI.Format.R32G32B32_Float;
}
for (int j = 0; j < inds.Count; j++)
{
indices.Add(inds[j] + vertexoffset);
}
DataStream posbuffer = new DataStream(assimpmesh.PositionPointer, assimpmesh.VerticesCount * 12, true, true);
DataStream normbuffer = new DataStream(assimpmesh.NormalsPointer, assimpmesh.VerticesCount * 12, true, true);
DataStream uvbuffer = null;
List<DataStream> uvbuffers = new List<DataStream>();
List<int> uvcounters = new List<int>();
for (int uvc = 0; uvc < assimpmesh.UvChannelCount;uvc++ )
{
uvbuffers.Add(new DataStream(assimpmesh.GetUvPointer(uvc), assimpmesh.VerticesCount * 12, true, true));
uvcounters.Add(this.GetUVChannelCount(assimpmesh, uvc));
}
if (assimpmesh.UvChannelCount > 0)
{
uvbuffer = new DataStream(assimpmesh.GetUvPointer(0), assimpmesh.VerticesCount * 12, true, true);
}
Vector3* pos = (Vector3*)posbuffer.DataPointer.ToPointer();
Vector3 accum = Vector3.Zero;
for (int j = 0; j < assimpmesh.VerticesCount; j++)
{
accum += pos[j];
}
Vector3 center = accum / assimpmesh.VerticesCount;
for (int j = 0; j < assimpmesh.VerticesCount; j++)
{
Pos3Norm3Tex2InstanceVertex vert = new Pos3Norm3Tex2InstanceVertex()
{
InstanceID = i,
Normals = normbuffer.Read<Vector3>(),
Position = posbuffer.Read<Vector3>(),
Center = center,
TexCoords = uvbuffer != null ? uvbuffer.Read<Vector2>() : Vector2.Zero
};
vertices.Add(vert);
for (int k = 0; k < assimpmesh.UvChannelCount; k++ )
{
var b = uvbuffers[k];
uvs.Add(b.Read<Vector2>());
if (uvcounters[k] == 3)
{
b.Read<float>();
}
}
if (uvbuffer != null && zuv) { uvbuffer.Read<float>(); }
}
vertexoffset += assimpmesh.VerticesCount;
}
}
DataStream vS = new DataStream(vertices.ToArray(), true, true);
vS.Position = 0;
DataStream iS = new DataStream(indices.ToArray(), true, true);
iS.Position = 0;
var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, vS, new BufferDescription()
{
BindFlags = BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = (int)vS.Length,
Usage = ResourceUsage.Default
//.........这里部分代码省略.........