コード例 #1
0
 private static void SetAlphaToOpaque(Image image)
 {
     using (var inputStream = new MemoryStream(image.Data, false))
         using (var reader = new BinaryReader(inputStream))
             using (var outputStream = new MemoryStream(image.Data, true))
                 using (var writer = new BinaryWriter(outputStream))
                 {
                     for (int y = 0; y < image.Height; y++)
                     {
                         TextureHelper.CopyScanline(reader, image.RowPitch, writer, image.RowPitch, image.Format, ScanlineFlags.SetAlpha);
                     }
                 }
 }
コード例 #2
0
        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);
                            }
                        }
                    }
        }