当前位置: 首页>>代码示例>>C#>>正文


C# Stream.WriteStruct方法代码示例

本文整理汇总了C#中Stream.WriteStruct方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.WriteStruct方法的具体用法?C# Stream.WriteStruct怎么用?C# Stream.WriteStruct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream的用法示例。


在下文中一共展示了Stream.WriteStruct方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Save

        public void Save(Stream stream)
        {
            stream.WriteUInt16((UInt16)Name.Length);
            stream.WriteAsciiString(Name);
            stream.WriteUInt8(ContainerType);
            stream.WriteUInt16((UInt16)Flags);
            stream.WriteUInt16((UInt16)Primitives.Count);
            stream.WriteUInt32(PackfileBaseOffset);
            stream.WriteUInt8(CompressionType);
            if (StubContainerParentName != null && StubContainerParentName != "")
            {
                stream.WriteUInt16((UInt16)StubContainerParentName.Length);
                stream.WriteAsciiString(StubContainerParentName);
            }
            else
            {
                stream.WriteUInt16(0);
            }
            stream.WriteInt32(AuxData.Length);
            stream.Write(AuxData, 0, AuxData.Length);
            stream.WriteInt32(TotalCompressedPackfileReadSize);

            foreach (WriteTimeSizes sizes in PrimitiveSizes)
            {
                stream.WriteStruct(sizes);
            }

            foreach (Primitive primitive in Primitives)
            {
                primitive.Save(stream);
            }
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:32,代码来源:Container.cs

示例2: WriteWave

        public void WriteWave(Stream Stream, StereoShortSoundSample[] Samples)
        {
            this.Stream = Stream;
            this.BinaryWriter = new BinaryWriter(Stream);

            WriteChunk("RIFF", () =>
            {
                Stream.WriteStringz("WAVE", 4, Encoding.ASCII);
                WriteChunk("fmt ", () =>
                {
                    Stream.WriteStruct(new WaveFormat()
                    {
                        CompressionCode = 1,
                        SampleRate = 44100,
                        NumberOfChannels = 2,
                        BytesPerSecond = 44100 * sizeof(short) * 2,
                        BlockAlignment = sizeof(short) * 2,
                        BitsPerSample = 16,
                        Padding = 0,
                    });
                });
                WriteChunk("data", () =>
                {
                    BinaryWriter.Write(PointerUtils.ArrayToByteArray(Samples));
                    /*
                    foreach (var Sample in Samples)
                    {
                        BinaryWriter.Write(Sample.Left);
                        BinaryWriter.Write(Sample.Right);
                    }
                    */
                });
            });
        }
开发者ID:soywiz,项目名称:cspspemu,代码行数:34,代码来源:Wav.cs

示例3: Save

        public void Save(Stream bnkStream, Stream mbnkStream)
        {
            Header.NumFiles = (uint)Files.Count;
            Header.HeaderSize = (uint)(Marshal.SizeOf(typeof(SoundbankHeader)) + (Marshal.SizeOf(typeof(SoundbankEntryInfo)) * Header.NumFiles));
            bnkStream.WriteStruct(Header);
            mbnkStream.WriteStruct(Header);
            uint nextOffset = Header.HeaderSize;
            nextOffset = nextOffset.Align(0x800);
            foreach (var entry in Files)
            {
                entry.Info.Offset = nextOffset;
                nextOffset += entry.Info.MetadataLength + entry.Info.AudioLength;
                nextOffset = nextOffset.Align(0x800);
                bnkStream.WriteStruct(entry.Info);
                mbnkStream.WriteStruct(entry.Info);
            }

            int count = 0;
            foreach (var entry in Files)
            {
                bnkStream.Seek(entry.Info.Offset, SeekOrigin.Begin);
                Stream metadataStream = m_MetadataStreams[count];
                if (metadataStream != null)
                {
                    metadataStream.Seek(0, SeekOrigin.Begin);
                    metadataStream.CopyTo(bnkStream);
                }
                Stream audioStream = m_AudioStreams[count];
                audioStream.CopyTo(bnkStream);
                count++;
            }

        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:33,代码来源:StreamingSoundbank.cs

示例4: WriteWave

        public void WriteWave(Stream Stream, short[] Samples)
        {
            this.Stream = Stream;
            this.BinaryWriter = new BinaryWriter(Stream);

            WriteChunk("RIFF", () =>
            {
                Stream.WriteStringz("WAVE", 4, Encoding.ASCII);
                WriteChunk("fmt ", () =>
                {
                    Stream.WriteStruct(new WaveFormat()
                    {
                        CompressionCode = 1,
                        SampleRate = 44100,
                        NumberOfChannels = 2,
                        BytesPerSecond = 44100 * sizeof(short) * 2,
                        BlockAlignment = sizeof(short) * 2,
                        BitsPerSample = 16,
                        Padding = 0,
                    });
                });
                WriteChunk("data", () =>
                {
                    foreach (var Sample in Samples) BinaryWriter.Write(Sample);
                });
            });
        }
开发者ID:mrcmunir,项目名称:cspspemu,代码行数:27,代码来源:Wav.cs

示例5: write

        public void write(Stream stream)
        {
            int writeIndex = 0;

            writeIndex += stream.WriteStruct(fileHeader);

            writeIndex += stream.WriteStruct(infoHeader);

            byte[] paddingBuffer = new byte[padding];

            // Avoid accessing the size properties too much
            uint _height = uheight;
            uint _width = width;
            uint _size = _height * _width;

            // Optimize loop if there is no adding
            if (paddingBuffer.Length > 0)
            {
                uint index = 0;
                for (uint i = 0; i < _height; i++)
                {
                    for (uint j = 0; j < _width; j++, index++)
                    {
                        BGR color = this[j, i];
                        writeIndex += stream.WriteStruct(color);
                    }

                    stream.Write(paddingBuffer, 0, paddingBuffer.Length);
                }
            }
            else
            {
                for (uint i = 0; i < _size; i++)
                {
                    BGR color = this[i];
                    writeIndex += stream.WriteStruct(color);
                }
            }
        }
开发者ID:jonanh,项目名称:dxtc,代码行数:39,代码来源:BMP.Parse.cs

示例6: Save

 public void Save(Stream s)
 {
     byte[] sectionData = null;
     using (MemoryStream ms = new MemoryStream())
     {
         foreach (Section section in Sections.Values)
         {
             section.Save(ms);
         }
         sectionData = ms.ToArray();
     }
     MainHeader.Checksum = Hashes.CrcVolition(sectionData);
     s.WriteStruct(MainHeader);
     s.Write(sectionData, 0, sectionData.Length);
 }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:15,代码来源:SaveFile.cs

示例7: Save

        public void Save(Stream stream)
        {
            Header.NumContainers = (short)Containers.Count;

            stream.WriteStruct(Header);

            // Write allocator types
            stream.WriteUInt32((uint)AllocatorTypes.Count);
            foreach (var pair in AllocatorTypes)
            {
                byte id = pair.Key;
                string name = pair.Value;
                stream.WriteUInt16((UInt16)name.Length);
                stream.WriteAsciiString(name);
                stream.WriteUInt8(id);
            }

            // Write primitive types
            stream.WriteUInt32((uint)PrimitiveTypes.Count);
            foreach (var pair in PrimitiveTypes)
            {
                byte id = pair.Key;
                string name = pair.Value;
                stream.WriteUInt16((UInt16)name.Length);
                stream.WriteAsciiString(name);
                stream.WriteUInt8(id);
            }

            // Write container types
            stream.WriteUInt32((uint)ContainerTypes.Count);
            foreach (var pair in ContainerTypes)
            {
                byte id = pair.Key;
                string name = pair.Value;
                stream.WriteUInt16((UInt16)name.Length);
                stream.WriteAsciiString(name);
                stream.WriteUInt8(id);
            }

            // Write containers
            foreach (Container container in Containers)
            {
                container.Save(stream);
            }
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:45,代码来源:Stream2File.cs

示例8: Save

 public void Save(Stream s)
 {
     s.WriteStruct<SaveGameSectionHeader>(Header);
     s.Write(Data, 0, Data.Length);
 }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:5,代码来源:Section.cs

示例9: Save

		public override void Save(Stream gifstream)
		{
			gifstream.WriteByte((byte)GifFlags.ImageSeparator);
			gifstream.WriteStruct(Header);
			if (LocalColorTableFlag)
			{
				for (var i = 0; i < LocalColorMap.Length; i++)
				{
					var entry = (Color24)LocalColorMap[i];
					gifstream.WriteStruct(entry);
				}
			}
			var enc = new GifLZWEncoder(8);
			var encbytes = enc.Compress(Frame.Bitmap8ToPixels());
			gifstream.WriteByte(8);
			var blocks = GifBitmap.MakeSubBlocks(encbytes);
			gifstream.Write(blocks, 0, blocks.Length);
		}
开发者ID:ramoneeza,项目名称:RopHelperSnippets,代码行数:18,代码来源:Rop.Gif.Sections.cs

示例10: Save

        public void Save(Stream stream)
        {
            // Calculate IndexSize
            FileData.IndexCount = (uint)Files.Count;
            FileData.IndexSize = (FileData.IndexCount * 0x1C);

            // Write Names & calculate NamesSize
            Dictionary<string, uint> filenames = new Dictionary<string, uint>(StringComparer.InvariantCultureIgnoreCase);
            stream.Seek(CalculateEntryNamesOffset(), SeekOrigin.Begin);
            uint filenameOffset = 0;
            foreach (PackfileEntry entry in Files)
            {
                string filename = Path.GetFileNameWithoutExtension(entry.Name);

                if (filenames.ContainsKey(filename))
                {
                    entry.Data.FilenameOffset = filenames[filename];
                }
                else
                {
                    entry.Data.FilenameOffset = filenameOffset;
                    int length = stream.WriteAsciiNullTerminatedString(filename);
                    filenames.Add(filename, filenameOffset);
                    filenameOffset += (uint)length;
                }

            }
            FileData.NamesSize = filenameOffset;
            
            // Write Extensions & calculate ExtensionsSize
            Dictionary<string, uint> extensions = new Dictionary<string, uint>(StringComparer.InvariantCultureIgnoreCase);
            uint extensionOffset = 0;
            stream.Seek(CalculateExtensionsOffset(), SeekOrigin.Begin);
            foreach (PackfileEntry entry in Files)
            {
                string extension = Path.GetExtension(entry.Name);
                if (extension.StartsWith("."))
                    extension = extension.Remove(0, 1);

                if (extensions.ContainsKey(extension))
                {
                    entry.Data.ExtensionOffset = extensions[extension];
                }
                else
                {
                    entry.Data.ExtensionOffset = extensionOffset;
                    int length = stream.WriteAsciiNullTerminatedString(extension);
                    extensions.Add(extension, extensionOffset);
                    extensionOffset += (uint)length;
                }
            }
            FileData.ExtensionsSize = extensionOffset;

            // Write data
            uint dataOffset = 0;
            stream.Seek(CalculateDataStartOffset(), SeekOrigin.Begin);
            foreach (PackfileEntry entry in Files)
            {
                Stream inStream = m_Streams[entry.Name];
                entry.Data.Size = (uint)inStream.Length;
                entry.Data.Start = dataOffset;
                entry.Data.CompressedSize = (uint)0xFFFFFFFF;
                inStream.CopyTo(stream);
                dataOffset += entry.Data.Size;
                stream.Align(16);
                dataOffset = dataOffset.Align(16);
            }

            // Write Header
            stream.Seek(0, SeekOrigin.Begin);
            FileData.Descriptor = 0x51890ACE;
            FileData.Version = 0x04;
            FileData.CompressedDataSize = 0xFFFFFFFF;
            FileData.UncompressedDataSize = dataOffset;
            FileData.PackageSize = (uint)stream.Length;
            stream.WriteStruct(FileData);
            
            // Write file index
            stream.Seek(GetEntryDataOffset(), SeekOrigin.Begin);
            foreach (PackfileEntry entry in Files)
            {
                stream.WriteStruct(entry.Data);
            }
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:84,代码来源:Packfile.cs

示例11: Save

        public void Save(Stream stream)
        {
            Header.Signature = 0x56414d44;
            Header.LipsyncOffset = 0;
            if (LipsyncData != null)
            {
                Header.LipsyncSize = (uint)LipsyncData.Length;
                stream.Seek(0x24, SeekOrigin.Begin);
                stream.Write(LipsyncData, 0, LipsyncData.Length);
            }
            else
                Header.LipsyncSize = 0;
            
            Header.SubtitleOffset = Header.LipsyncSize;

            uint startOfSubtitles = 0x24 + Header.LipsyncSize + 0x74;

            uint nextSubtitleOffset = 0;

            if (Subtitles.Count != 0)
            {
                SubtitleHeader = new AudioMetadataSubtitleHeader();
                SubtitleHeader.Version = 3;
                SubtitleHeader.LocalizedVoiceSubtitleHeaders = new LocalizedVoiceSubtitleHeader[14];
                for (int i = 0; i < SubtitleHeader.LocalizedVoiceSubtitleHeaders.Length; i++)
                {
                    Language language = (Language)i;

                    string subtitle = Subtitles[language];
                    if (subtitle == "")
                    {
                        SubtitleHeader.LocalizedVoiceSubtitleHeaders[i].Offset = nextSubtitleOffset;
                        SubtitleHeader.LocalizedVoiceSubtitleHeaders[i].Length = 0;
                    }
                    else
                    {
                        var map = LanguageUtility.GetEncodeCharMap(Instance, language);

                        byte[] subtitleData;
                        using (MemoryStream ms = new MemoryStream())
                        {
                            for (int pos = 0; pos < subtitle.Length; pos++)
                            {
                                char src = subtitle[pos];
                                char value = src;
                                if (map.ContainsKey(src))
                                    value = map[src];

                                byte[] data = BitConverter.GetBytes(value);
                                ms.Write(data, 0, data.Length);
                            }
                            ms.WriteUInt16(0);
                            subtitleData = ms.ToArray();
                        }
                        SubtitleHeader.LocalizedVoiceSubtitleHeaders[i].Offset = nextSubtitleOffset;
                        SubtitleHeader.LocalizedVoiceSubtitleHeaders[i].Length = (uint)subtitleData.Length;
                        stream.Seek(startOfSubtitles + nextSubtitleOffset, SeekOrigin.Begin);
                        stream.Write(subtitleData, 0, subtitleData.Length);

                        nextSubtitleOffset += (uint)subtitleData.Length;
                    }
                }
                Header.SubtitleSize = nextSubtitleOffset + 0x74;
                stream.Seek(0x24 + Header.SubtitleOffset, SeekOrigin.Begin);
                stream.WriteStruct(SubtitleHeader);
            }
            else
            {
                Header.SubtitleSize = 0;
            }
            stream.Seek(0, SeekOrigin.Begin);
            stream.WriteStruct(Header);
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:73,代码来源:AudioMetadata.cs

示例12: Save

        public static void Save(Image image, Stream stream)
        {
            if (image == null)
            throw new ArgumentNullException("image");
              if (stream == null)
            throw new ArgumentNullException("stream");

              var convFlags = ConversionFlags.None;
              var header = EncodeTgaHeader(image, ref convFlags);

              // Write header.
              stream.WriteStruct(header);

              // Determine memory required for image data.
              int rowPitch = (convFlags & ConversionFlags.Format888) != 0 ? image.Width * 3 : image.RowPitch;

              // Write pixels.
              using (var sourceStream = new MemoryStream(image.Data, false))
              using (var reader = new BinaryReader(sourceStream))
            #if NET45
              using (var writer = new BinaryWriter(stream, Encoding.Default, true))
            #else
              using (var writer = new BinaryWriter(stream, Encoding.Default))   // Warning: Closes the stream!
            #endif
              {
            for (int y = 0; y < image.Height; y++)
            {
              if ((convFlags & ConversionFlags.Format888) != 0)
              {
            Copy24BppScanline(reader, image.RowPitch, writer);
              }
              else if ((convFlags & ConversionFlags.Swizzle) != 0)
              {
            TextureHelper.SwizzleScanline(reader, image.RowPitch, writer, rowPitch, image.Format, ScanlineFlags.None);
              }
              else
              {
            TextureHelper.CopyScanline(reader, image.RowPitch, writer, rowPitch, image.Format, ScanlineFlags.None);
              }
            }
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:42,代码来源:TgaHelper.cs

示例13: write

        public void write(Stream stream)
        {
            int writeIndex = 0;

            // Add the file signature
            writeIndex += stream.WriteStruct(new DDS_Magic() { dwMagic = Magic });

            writeIndex += stream.WriteStruct(ddsHeader);

            // Only write the ddsHeaderDXT10 when the FOURCC.DX10 is set
            if (ddsHeader.ddspf.dwFourCC == DDS_PIXELFORMAT.FOURCC.DX10)
            {
                writeIndex += stream.WriteStruct(ddsHeaderDXT10);
            }

            foreach (var block in blocks)
            {
                DDS_DXT1Block structBlock = block;
                stream.WriteStruct(structBlock);
            }
        }
开发者ID:jonanh,项目名称:dxtc,代码行数:21,代码来源:DDS.Parse.cs


注:本文中的Stream.WriteStruct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。