У меня есть форма, которая может показать гистограмму picturebox.Image
. А потом я добавил ползунок яркости, и он работает. Но после того, как я отрегулирую яркость изображения, гистограмма не меняется. Как я могу изменить гистограмму в зависимости от яркости изображения?
Я попытался повторно выполнить кнопку гистограммы, и она все еще не меняется. Яркость и гистограмма находятся в другом классе / форме. Извините, еще новичок ie по обработке изображений.
- Фактическая диаграмма гистограммы
- Вот после того, как я повторно выполню кнопку гистограммы. Все та же гистограмма
Mainform.cs
Bitmap newBit; //initialize new Bitmap
//Open the image with Dialogresult
private void openImage_Click(object sender, EventArgs e)
{
OpenFileDialog img = new OpenFileDialog();
if (img.ShowDialog() == DialogResult.OK) {
pbOutput.Image = new Bitmap(img.FileName); //I take this image from picturebox
newBit = new Bitmap(img.FileName);
}
//for adjusting slider
private void bBar_Scroll(object sender, EventArgs e)
{
brighText.Text = bScroll.Value.ToString();
pbOutput.Image = adjustBrightness(newBit, bScroll.Value);
}
//brightness method (color matrix)
public static Bitmap adjustBrightness(Bitmap Image, int value)
{
Bitmap tempBit = Image;
float v = value / 255.0f;
Bitmap newBit = new Bitmap(tempBit.Width, tempBit.Height);
Graphics newGraphics = Graphics.FromImage(newBit);
float[][] f = {
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[] {v, v, v, 1, 1}
};
ColorMatrix newMatrix = new ColorMatrix(f);
ImageAttributes a = new ImageAttributes();
a.SetColorMatrix(newMatrix);
newGraphics.DrawImage(tempBit, new Rectangle(0, 0, tempBit.Width, tempBit.Height), 0, 0, tempBit.Width, tempBit.Height, GraphicsUnit.Pixel, a);
return newBit;
}
Histogram.cs
public Histogram(Image image)
{
Bitmap b = new Bitmap(image);
String[] seriesArray = { "Red", "Green", "Blue" };
int[] pointsArray = { 1, 2, 3 };
int[] histogram_r = new int[256];
int[] histogram_g = new int[256];
int[] histogram_b = new int[256];
float max = 0;
for (int i = 0; i < b.Width; i++) {
for (int j = 0; j < b.Height; j++) {
int redValue = b.GetPixel(i, j).R;
int greenValue = b.GetPixel(i, j).G;
int blueValue = b.GetPixel(i, j).B;
histogram_r[redValue]++;
histogram_g[greenValue]++;
histogram_b[blueValue]++;
if (max < histogram_r[redValue])
max = histogram_r[redValue];
if (max < histogram_g[greenValue])
max = histogram_g[greenValue];
if (max < histogram_b[blueValue])
max = histogram_b[blueValue];
}
}
histChart.Titles.Add("RGB Histogram");
for (int j = 0; j < seriesArray.Length; j++) {
Series series = histChart.Series.Add(seriesArray[j]);
for (int i = 0; i < histogram_r.Length; i++) {
if (j == 0) {
series.Points.Add(histogram_r[i]);
}
else if (j == 1) {
series.Points.Add(histogram_g[i]);
}
else {
series.Points.Add(histogram_b[i]);
}
}
}
}