Изменение контраста bitmap - C#
Формулировка задачи:
public System.Drawing.Bitmap Apply(Bitmap bmpImg)
{
var BrightnessContrastImage = new Bitmap(bmpImg.Width, bmpImg.Height);
{
UInt32 p;
for (int i = 0; i < bmpImg.Height; i++)
for (int j = 0; j < bmpImg.Width; j++)
{
p = BrightnessContrast.core.BrightnessContrast.Brightness(BrightnessContrastImage.pixel[i, j]/*ERROR*/, BrightnessContrastThreshhold);
BrightnessContrastImage.FromOnePixelToBitmap/*ERROR*/(i, j, p);
}
FromBitmapToScreen(); //ERROR
}
}Решение задачи: «Изменение контраста bitmap»
textual
Листинг программы
class ImageColorMatrixTool
{
public Bitmap Transform(Image img, float brightness, float contrast, float saturation)
{
var imageAttributes = new ImageAttributes();
var b = brightness;
var c = contrast;
var t = (1f - c) / 2f;
var s = saturation;
var sr = (1 - s) * 0.3086f;
var sg = (1 - s) * 0.6094f;
var sb = (1 - s) * 0.0820f;
float[][] colorMatrixElements = {
new float[] {c*(sr+s), c*sr, c*(sr), 0, 0},
new float[] {c*sg, c*(sg+s), c*(sg), 0, 0},
new float[] {c*sb, c*sb, c*(sb+s), 0, 0},
new float[] {0, 0, 0, 1f, 0},
new float[] {t+b, t+b, t+b, 0, 1}};
var colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
var result = new Bitmap(img.Width, img.Height);
using (var gr = Graphics.FromImage(result))
gr.DrawImage(img,
new Rectangle(0, 0, img.Width, img.Height), 0, 0,
img.Width, img.Height,
GraphicsUnit.Pixel, imageAttributes);
return result;
}
}
}