Write() public method

public Write ( BinaryWriter writer ) : void
writer System.IO.BinaryWriter
return void
Example #1
0
        public void Save(Stream output, DdsSaveConfig saveConfig)
        {
            BinaryWriter writer = new BinaryWriter(output);

            header = new DdsHeader(saveConfig, Width, Height);
            header.Write(writer);

            if (saveConfig.GenerateMipMaps)
            {
                GenerateMipMaps();
            }

            foreach (DdsMipMap mipMap in MipMaps.OrderByDescending(mip => mip.Width))
            {
                byte[] outputData = WriteMipMap(mipMap, saveConfig);

                output.Write(outputData, 0, outputData.Length);
            }

            output.Flush();
        }
Example #2
0
    public void Save(Stream output, DdsSaveConfig saveConfig) {
      BinaryWriter writer = new BinaryWriter(output);

      header = new DdsHeader(saveConfig, Width, Height);

      header.Write(writer);

      if (saveConfig.GenerateMipMaps) GenerateMipMaps();

      foreach(DdsMipMap mipMap in MipMaps.OrderByDescending(mip => mip.Width)) {
        byte[] outputData = WriteMipMap(mipMap, saveConfig);

        output.Write(outputData, 0, outputData.Length);
      }

      output.Flush();
    }
    private Stream buildDdsImage(int mipMapIndex, out FileFormat imageFormat) {
      DomainPropertyByteValue formatProp = PropertyHeader.GetProperty("Format").FirstOrDefault()?.Value as DomainPropertyByteValue;

      imageFormat = FileFormat.Unknown;

      if (formatProp == null) return null;

      string format = formatProp.PropertyString;

      DomainMipMap mipMap = MipMaps[mipMapIndex];

      imageFormat = DdsPixelFormat.ParseFileFormat(format);

      DdsHeader ddsHeader = new DdsHeader(new DdsSaveConfig(imageFormat, 0, 0, false, false), mipMap.Width, mipMap.Height);

      MemoryStream stream = new MemoryStream();

      BinaryWriter writer = new BinaryWriter(stream);

      ddsHeader.Write(writer);

      stream.Write(mipMap.ImageData, 0, mipMap.ImageData.Length);

      stream.Flush();

      stream.Position = 0;

      return stream;
    }