I'm building some software that requires image panning, zooming, and brightness controls. I set up a small project to to build a simple brightness control after finding a lot of examples online, so please ignore that I'm doing everything in the main form
When I start to use the trackbar controller, which fires the event below when the value (-100 to 100) is changed, memory usage stacks up into the Gigabytes in seconds. It'll then sit there and never free the memory. Moving the trackbar again eats up even more memory
private void trackBarBrightness_EditValueChanged(object sender, EventArgs e)
{
float value = trackBarBrightness.Value * 0.01f;
float[][] colorMatrixElements =
{
new float[] {
1,
0,
0,
0,
0
},
new float[] {
0,
1,
0,
0,
0
},
new float[] {
0,
0,
1,
0,
0
},
new float[] {
0,
0,
0,
1,
0
},
new float[] {
value,
value,
value,
0,
1
}
};
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
ImageAttributes imageAttributes = new ImageAttributes();
imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
//Image img = this.pictureEdit.Image;
Image img = originalImage;
Graphics g = default(Graphics);
Bitmap bm = new Bitmap(Convert.ToInt32(img.Width), Convert.ToInt32(img.Height));
g = Graphics.FromImage(bm);
g.DrawImage(img, new Rectangle(0, 0, bm.Width, bm.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel, imageAttributes);
pictureEdit.Image = bm;
}
Any guidance would be much appreciated