Browse Source

Fix memory leak in BitmapEncoder

Former-commit-id: a64b965aef7ff28b675e858aa26dfdae6312a9f2
Former-commit-id: df2197d0e4fac1983ad20db07df4b9207dc1a3f0
Former-commit-id: 76331f4ca8bf74412456de842b6fbc86533b8203
af/merge-core
James Jackson-South 10 years ago
parent
commit
1039787629
  1. 54
      src/ImageProcessor/Formats/Bmp/BmpEncoder.cs

54
src/ImageProcessor/Formats/Bmp/BmpEncoder.cs

@ -51,35 +51,36 @@ namespace ImageProcessor.Formats
rowWidth += 4 - amount;
}
BinaryWriter writer = new BinaryWriter(stream);
BmpFileHeader fileHeader = new BmpFileHeader
using (BinaryWriter writer = new BinaryWriter(stream))
{
Type = 19778, // BM
Offset = 54,
FileSize = 54 + (image.Height * rowWidth * 3)
};
BmpFileHeader fileHeader = new BmpFileHeader
{
Type = 19778, // BM
Offset = 54,
FileSize = 54 + (image.Height * rowWidth * 3)
};
WriteHeader(writer, fileHeader);
WriteHeader(writer, fileHeader);
BmpInfoHeader infoHeader = new BmpInfoHeader
{
HeaderSize = 40,
Height = image.Height,
Width = image.Width,
BitsPerPixel = 24,
Planes = 1,
Compression = BmpCompression.RGB,
ImageSize = image.Height * rowWidth * 3,
ClrUsed = 0,
ClrImportant = 0
};
WriteInfo(writer, infoHeader);
this.WriteImage(writer, image);
writer.Flush();
BmpInfoHeader infoHeader = new BmpInfoHeader
{
HeaderSize = 40,
Height = image.Height,
Width = image.Width,
BitsPerPixel = 24,
Planes = 1,
Compression = BmpCompression.RGB,
ImageSize = image.Height * rowWidth * 3,
ClrUsed = 0,
ClrImportant = 0
};
WriteInfo(writer, infoHeader);
this.WriteImage(writer, image);
writer.Flush();
}
}
/// <summary>
@ -100,6 +101,7 @@ namespace ImageProcessor.Formats
amount = 4 - amount;
}
// TODO: Make this parallel.
for (int y = image.Height - 1; y >= 0; y--)
{
for (int x = 0; x < image.Width; x++)

Loading…
Cancel
Save