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; 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