Browse Source

Fix memory leak in BitmapEncoder

Former-commit-id: 064795cce7107001df5fd8adc610b7d8d19ef7dc
Former-commit-id: d142c5bd63ad62e9307f80d42765d21d3a37e5e3
Former-commit-id: 9448861fae461c940d7fb493a44960c1f6238f13
af/merge-core
James Jackson-South 10 years ago
parent
commit
3ca60efc9b
  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; rowWidth += 4 - amount;
} }
BinaryWriter writer = new BinaryWriter(stream); using (BinaryWriter writer = new BinaryWriter(stream))
BmpFileHeader fileHeader = new BmpFileHeader
{ {
Type = 19778, // BM BmpFileHeader fileHeader = new BmpFileHeader
Offset = 54, {
FileSize = 54 + (image.Height * rowWidth * 3) Type = 19778, // BM
}; Offset = 54,
FileSize = 54 + (image.Height * rowWidth * 3)
};
WriteHeader(writer, fileHeader); WriteHeader(writer, fileHeader);
BmpInfoHeader infoHeader = new BmpInfoHeader BmpInfoHeader infoHeader = new BmpInfoHeader
{ {
HeaderSize = 40, HeaderSize = 40,
Height = image.Height, Height = image.Height,
Width = image.Width, Width = image.Width,
BitsPerPixel = 24, BitsPerPixel = 24,
Planes = 1, Planes = 1,
Compression = BmpCompression.RGB, Compression = BmpCompression.RGB,
ImageSize = image.Height * rowWidth * 3, ImageSize = image.Height * rowWidth * 3,
ClrUsed = 0, ClrUsed = 0,
ClrImportant = 0 ClrImportant = 0
}; };
WriteInfo(writer, infoHeader); WriteInfo(writer, infoHeader);
this.WriteImage(writer, image); this.WriteImage(writer, image);
writer.Flush(); writer.Flush();
}
} }
/// <summary> /// <summary>
@ -100,6 +101,7 @@ namespace ImageProcessor.Formats
amount = 4 - amount; amount = 4 - amount;
} }
// TODO: Make this parallel.
for (int y = image.Height - 1; y >= 0; y--) for (int y = image.Height - 1; y >= 0; y--)
{ {
for (int x = 0; x < image.Width; x++) for (int x = 0; x < image.Width; x++)

Loading…
Cancel
Save