本文整理汇总了C#中System.IO.BinaryWriter.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryWriter.Seek方法的具体用法?C# System.IO.BinaryWriter.Seek怎么用?C# System.IO.BinaryWriter.Seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryWriter
的用法示例。
在下文中一共展示了System.IO.BinaryWriter.Seek方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRaw
static void TestRaw()
{
using (var vorbis = new NVorbis.VorbisReader(@"..\..\..\TestFiles\2test.ogg"))
using (var outFile = System.IO.File.Create(@"..\..\..\TestFiles\2test.wav"))
using (var writer = new System.IO.BinaryWriter(outFile))
{
writer.Write(Encoding.ASCII.GetBytes("RIFF"));
writer.Write(0);
writer.Write(Encoding.ASCII.GetBytes("WAVE"));
writer.Write(Encoding.ASCII.GetBytes("fmt "));
writer.Write(18);
writer.Write((short)1); // PCM format
writer.Write((short)vorbis.Channels);
writer.Write(vorbis.SampleRate);
writer.Write(vorbis.SampleRate * vorbis.Channels * 2); // avg bytes per second
writer.Write((short)(2 * vorbis.Channels)); // block align
writer.Write((short)16); // bits per sample
writer.Write((short)0); // extra size
writer.Write(Encoding.ASCII.GetBytes("data"));
writer.Flush();
var dataPos = outFile.Position;
writer.Write(0);
var buf = new float[vorbis.SampleRate / 10 * vorbis.Channels];
int count;
while ((count = vorbis.ReadSamples(buf, 0, buf.Length)) > 0)
{
for (int i = 0; i < count; i++)
{
var temp = (int)(32767f * buf[i]);
if (temp > 32767)
{
temp = 32767;
}
else if (temp < -32768)
{
temp = -32768;
}
writer.Write((short)temp);
}
}
writer.Flush();
writer.Seek(4, System.IO.SeekOrigin.Begin);
writer.Write((int)(outFile.Length - 8L));
writer.Seek((int)dataPos, System.IO.SeekOrigin.Begin);
writer.Write((int)(outFile.Length - dataPos - 4L));
writer.Flush();
}
}
示例2: Assemble
public static void Assemble(string infile, string outfile, string origin)
{
CurrentNdx = 0;
AsLength = Convert.ToUInt16(origin, 16);
IsEnd = false;
ExecutionAddress = 0;
LabelTable = new System.Collections.Hashtable(50);
System.IO.BinaryWriter output;
System.IO.TextReader input;
System.IO.FileStream fs = new System.IO.FileStream(outfile, System.IO.FileMode.Create);
output = new System.IO.BinaryWriter(fs);
input = System.IO.File.OpenText(infile);
SourceProgram = input.ReadToEnd();
input.Close();
output.Write('B');
output.Write('3');
output.Write('2');
output.Write(Convert.ToUInt16(origin, 16));
output.Write((ushort)0);
Parse(output, origin);
output.Seek(5, System.IO.SeekOrigin.Begin);
output.Write(ExecutionAddress);
output.Close();
fs.Close();
}
示例3: CreateElf64File
/// <summary>
/// Creates the elf32 file.
/// </summary>
/// <param name="compiler">The compiler.</param>
private void CreateElf64File(Mosa.Runtime.CompilerFramework.AssemblyCompiler compiler)
{
using (System.IO.FileStream fs = new System.IO.FileStream(this.OutputFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
{
Elf64Header header = new Elf64Header();
header.Type = Elf64FileType.Executable;
header.Machine = Elf64MachineType.Intel386;
header.SectionHeaderNumber = (ushort)(Sections.Count + 2);
header.SectionHeaderOffset = header.ElfHeaderSize;
header.CreateIdent(Elf64IdentClass.Class64, Elf64IdentData.Data2LSB, null);
// Calculate the concatenated size of all section's data
uint offset = 0;
foreach (Mosa.Runtime.Linker.Elf64.Sections.Elf64Section section in Sections)
{
offset += (uint)section.Length;
}
offset += (uint)nullSection.Length;
offset += (uint)stringTableSection.Length;
// Calculate offsets
header.ProgramHeaderOffset = (uint)header.ElfHeaderSize + (uint)header.SectionHeaderEntrySize * (uint)header.SectionHeaderNumber + offset;
header.SectionHeaderStringIndex = (ushort)((ushort)header.ProgramHeaderOffset + (ushort)header.ProgramHeaderNumber * (ushort)header.ProgramHeaderEntrySize);
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(fs);
// Write the ELF Header
header.Write(writer);
// Overjump the Section Header Table and write the section's data first
long tmp = fs.Position;
writer.Seek((int)(tmp + header.SectionHeaderNumber * header.SectionHeaderEntrySize), System.IO.SeekOrigin.Begin);
nullSection.Write(writer);
stringTableSection.Write(writer);
// Write the sections
foreach (Mosa.Runtime.Linker.Elf64.Sections.Elf64Section section in Sections)
section.Write(writer);
// Jump back to the Section Header Table
writer.Seek((int)tmp, System.IO.SeekOrigin.Begin);
nullSection.WriteHeader(writer);
stringTableSection.WriteHeader(writer);
// Write the section headers
foreach (Mosa.Runtime.Linker.Elf64.Sections.Elf64Section section in Sections)
section.WriteHeader(writer);
}
}
示例4: CreateElf32File
/// <summary>
/// Creates the elf32 file.
/// </summary>
/// <param name="compiler">The compiler.</param>
private void CreateElf32File(CompilerFramework.AssemblyCompiler compiler)
{
using (System.IO.FileStream fs = new System.IO.FileStream(OutputFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None)) {
Elf32Header header = new Elf32Header();
header.Type = Elf32FileType.Executable;
header.Machine = Elf32MachineType.Intel386;
header.SectionHeaderNumber = (ushort)(Sections.Count + 2);
header.SectionHeaderOffset = header.ElfHeaderSize;
header.CreateIdent(Elf32IdentClass.Class32, Elf32IdentData.Data2LSB, null);
// Calculate the concatenated size of all section's data
uint offset = 0;
foreach (Elf32Section section in Sections) {
offset += (uint)section.Length;
}
offset += (uint)_nullSection.Length;
offset += (uint)_stringTableSection.Length;
// Calculate offsets
header.ProgramHeaderOffset = header.ElfHeaderSize + header.SectionHeaderEntrySize * (uint)header.SectionHeaderNumber + offset;
header.ProgramHeaderNumber = 1;
header.SectionHeaderStringIndex = 1;
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(fs);
// Write the ELF Header
header.Write(writer);
// Overjump the Section Header Table and write the section's data first
long tmp = fs.Position;
writer.Seek((int)(tmp + header.SectionHeaderNumber * header.SectionHeaderEntrySize), System.IO.SeekOrigin.Begin);
_nullSection.Write(writer);
_stringTableSection.Write(writer);
// Write the _sections
foreach (Elf32Section section in Sections)
section.Write(writer);
// Jump back to the Section Header Table
writer.Seek((int)tmp, System.IO.SeekOrigin.Begin);
_nullSection.WriteHeader(writer);
_stringTableSection.WriteHeader(writer);
// Write the section headers
foreach (Elf32Section section in Sections)
section.WriteHeader(writer);
Elf32ProgramHeader pheader = new Elf32ProgramHeader
{
Alignment = 0,
FileSize = (uint)GetSection(SectionKind.Text).Length
};
pheader.MemorySize = pheader.FileSize;
pheader.VirtualAddress = 0xFF0000;
pheader.Flags = Elf32ProgramHeaderFlags.Execute | Elf32ProgramHeaderFlags.Read | Elf32ProgramHeaderFlags.Write;
pheader.Offset = ((Elf32Section)GetSection(SectionKind.Text)).Header.Offset;
pheader.Type = Elf32ProgramHeaderType.Load;
writer.Seek((int)header.ProgramHeaderOffset, System.IO.SeekOrigin.Begin);
pheader.Write(writer);
}
}
示例5: button2_Click
//.........这里部分代码省略.........
else
{
stream2.Write(".");
pattern[MaxColoursPerRow * row + i, stitch] = 0;
}
}
stream2.WriteLine();
}
}
stream2.Close();
// Now create binary array in brother format, 1 bit per pixel
Byte[,] patternOut = new Byte[bmp.Height * MaxColoursPerRow, widthInBits / 8];
for (int row = 0; row < bmp.Height * MaxColoursPerRow; row++)
{
Byte bit = 0;
for (int stitch = 0; stitch < widthInBits; stitch++)
{
bit = (Byte)(stitch & 0x07);
bit = (Byte)(0x80 >> bit);
if (pattern[row, stitch] != 0)
{
patternOut[row, stitch / 8] = (Byte)(patternOut[row, stitch / 8] | ( bit) );
}
// patternOut[row, stitch / 8] = (Byte)(patternOut[row, stitch / 8] | ((pattern[row, stitch] == 0) ? 0 : (2 ^ bit) ));
}
}
System.IO.FileStream fs = new System.IO.FileStream("C:\\Knitulator\\track-01.dat", System.IO.FileMode.OpenOrCreate);
System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(fs);
binaryWriter.Seek(0, System.IO.SeekOrigin.Begin);
binaryWriter.Write((Byte)0x01);
binaryWriter.Write((Byte)0x20);
Byte heightHundreds = (Byte)((bmp.Height * MaxColoursPerRow) / 100);
Byte heightTens = (Byte)(((bmp.Height * MaxColoursPerRow) / 10) - (10 * heightHundreds));
Byte heightUnits = (Byte)((bmp.Height * MaxColoursPerRow) - (10 * heightTens) - (100 * heightHundreds));
Byte widthHundreds = (Byte)((widthInBits) / 100);
Byte widthTens = (Byte)(((widthInBits) / 10) - (10 * widthHundreds));
Byte widthUnits = (Byte)((widthInBits) - (10 * widthTens) - (100 * widthHundreds));
//binaryWriter.Write((Byte)0x77);//774 high
//binaryWriter.Write((Byte)0x41);
//binaryWriter.Write((Byte)0x74);// 174 wide
binaryWriter.Write((Byte)((heightHundreds << 4) + heightTens));
binaryWriter.Write((Byte)((heightUnits << 4) + widthHundreds));
binaryWriter.Write((Byte)((widthTens << 4) + widthUnits));
binaryWriter.Write((Byte)0x89);// 89
binaryWriter.Write((Byte)0x01);//01 = pattern mode 8 number 901
binaryWriter.Write((Byte)0x00);
binaryWriter.Write((Byte)0x00);
binaryWriter.Write((Byte)0x00);
binaryWriter.Write((Byte)0x00);
binaryWriter.Write((Byte)0x00);
binaryWriter.Write((Byte)0x09);
binaryWriter.Write((Byte)0x02);
//fs.Position = 0x7ee0 - (patternRowColour.Length / 2) - (bmp.Height * MaxColoursPerRow * widthInBits / 8);
//binaryWriter = new System.IO.BinaryWriter(fs);
示例6: button1_Click_1
//.........这里部分代码省略.........
stream.Close();
// Now lets create a 2 colour pattern, where each row contains a boolean indicating do or don't use the contrast yarn.
int widthInBits = (int)(8 * Math.Round(bmp.Width / (double)8, MidpointRounding.AwayFromZero)); // must be multiple of 8 bits
Byte[,] pattern = new Byte[bmp.Height, widthInBits]; // Array to hold pattern data = 1 byte represents 8 stitches
System.IO.StreamWriter stream2 = new System.IO.StreamWriter("C:\\Knitulator\\2col.txt");
int n = bmp.Height;
stream2.WriteLine("Row : Row Pattern");
for (int row = 0; row < bmp.Height; row++)
{
stream2.Write((bmp.Height - row).ToString("D3") + " : ");
n--;
for (int stitch = 0; stitch < bmp.Width; stitch++)
{
if (output[row, stitch] == 2)
{
stream2.Write("X");
pattern[row, stitch] = 1;
}
else
{
stream2.Write(".");
pattern[row, stitch] = 0;
}
}
stream2.WriteLine();
}
stream2.Close();
// Now create binary array in brother format, 1 bit per pixel
Byte[,] patternOut = new Byte[bmp.Height, widthInBits / 8];
for (int row = 0; row < bmp.Height; row++)
{
Byte bit = 0;
for (int stitch = 0; stitch < widthInBits; stitch++)
{
bit = (Byte)(stitch & 0x07);
bit = (Byte)(0x80 >> bit);
patternOut[row, stitch / 8] = (Byte)(patternOut[row, stitch / 8] | ((2 ^ bit) * pattern[row, stitch]));
}
}
System.IO.FileStream fs = new System.IO.FileStream("C:\\Knitulator\\track-01.dat", System.IO.FileMode.OpenOrCreate);
System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(fs);
binaryWriter.Seek(0, System.IO.SeekOrigin.Begin);
binaryWriter.Write((Byte)0x01);
binaryWriter.Write((Byte)0x20);
Byte heightHundreds = (Byte)((bmp.Height) / 100);
Byte heightTens = (Byte)(((bmp.Height) / 10) - (10 * heightHundreds));
Byte heightUnits = (Byte)((bmp.Height) - (10 * heightTens) - (100 * heightHundreds));
Byte widthHundreds = (Byte)((widthInBits) / 100);
Byte widthTens = (Byte)(((widthInBits) / 10) - (10 * widthHundreds));
Byte widthUnits = (Byte)((widthInBits) - (10 * widthTens) - (100 * widthHundreds));
binaryWriter.Write((Byte)((heightHundreds << 4) + heightTens));
binaryWriter.Write((Byte)((heightUnits << 4) + widthHundreds));
binaryWriter.Write((Byte)((widthTens << 4) + widthUnits));
binaryWriter.Write((Byte)0x49);// 49
binaryWriter.Write((Byte)0x01);//01 = pattern mode 8 number 901
binaryWriter.Write((Byte)0x00);
binaryWriter.Write((Byte)0x00);
binaryWriter.Write((Byte)0x00);
binaryWriter.Write((Byte)0x00);
binaryWriter.Write((Byte)0x00);
binaryWriter.Write((Byte)0x09);
binaryWriter.Write((Byte)0x02);
binaryWriter.Seek(0x7ee0 - (bmp.Height * widthInBits / 8), System.IO.SeekOrigin.Begin);
for (int row = 0; row < bmp.Height ; row++)
{
for (int stitchBlock = 0; stitchBlock < widthInBits / 8; stitchBlock++)
{
binaryWriter.Write(patternOut[row, stitchBlock]);
Console.Write(patternOut[row, stitchBlock].ToString("X2") + " ");
}
Console.WriteLine();
}
binaryWriter.Close();
fs.Close();
MessageBox.Show("Conversion Complete.");
}