Mam do zrobienia jasność, kontrast i gamma. Jasność i gamma jest ok działa jak trzeba, ale z kontrastem niby mam problem bo problem jest gdy daje na max wartość to mi czarny obrazek się robi i to samo jak dam minimalną wartością.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private byte[] LUT = new byte[256];//look-up-table
Bitmap image = new Bitmap(1,1);
public Form1()
{
InitializeComponent();
}
//ładowanie obrazka do picturebox
private void LoadImage_Click(object sender, EventArgs e)
{
OpenFileDialog wczytajobrazplik = new OpenFileDialog();
wczytajobrazplik.Multiselect = false;
wczytajobrazplik.Filter = "JPEG (*.jpg)|*.jpg|PNG (*.png)|*.png|BMP (*.bmp)|*.bmp";
if (wczytajobrazplik.ShowDialog() != DialogResult.Cancel)
{
if (wczytajobrazplik.FileName != null)
{
image = new Bitmap(wczytajobrazplik.FileName);
}
pictureBox1.Image = image;
this.panel1.Enabled = true;
}
}
private void LUT_Red_Green_Blue()
{
int LRGB, Red, Green, Blue;
Color c;
Bitmap image2 = new Bitmap(image.Width, image.Height);
for (int i = 0; i < 256; i++)
{
//jasnośc(-255,255) domyślnie 0
LRGB = i + jasnoscTrackBar.Value;
if (LRGB > 255)
{
LRGB = 255;
}
if (LRGB < 0)
{
LRGB = 0;
}
//kontrast(-127,127) domyślnie 0
if (kontrastTrackBar.Value > 0)
{
LRGB = (int)((127.0 / (127.0 - kontrastTrackBar.Value)) * (LRGB - kontrastTrackBar.Value));
}
else if (kontrastTrackBar.Value <= 0)
{
LRGB = (int)((127.0 + kontrastTrackBar.Value) / 127.0 * (LRGB - kontrastTrackBar.Value));
}
if (LRGB > 255)
{
LRGB = 255;
}
if (LRGB < 0)
{
LRGB = 0;
}
//gamma(0,500) domyślnie 100
LRGB = (int)(255.0 * Math.Pow((LRGB / 255.0), (1.0 / (gammaTrackBar.Value / 100.0))));
if (LRGB > 255)
{
LRGB = 255;
}
if (LRGB < 1)
{
LRGB = 0;
}
LUT[i] = (byte)LRGB;
}
for (int x = 0; x != pictureBox1.Image.Width; x++)
{
for (int y = 0; y != pictureBox1.Image.Height; y++)
{
c = image.GetPixel(x, y);
Red = LUT[c.R];
Green = LUT[c.G];
Blue = LUT[c.B];
image2.SetPixel(x, y, Color.FromArgb(Red, Green, Blue));
}
}
pictureBox1.Image = image2;
}
private void trackBar_MouseUp(object sender, MouseEventArgs e)
{
LUT_Red_Green_Blue();
numericUpDown1.Value = jasnoscTrackBar.Value;
numericUpDown2.Value = kontrastTrackBar.Value;
numericUpDown3.Value = gammaTrackBar.Value;
}
private void numericUpDown_ValueChanged(object sender, EventArgs e)
{
LUT_Red_Green_Blue();
jasnoscTrackBar.Value = (int)numericUpDown1.Value;
kontrastTrackBar.Value = (int)numericUpDown2.Value;
gammaTrackBar.Value = (int)numericUpDown3.Value;
}
}
}
nie wiem co robi mi źle przy kontraście i jakby ktoś mógł to niech mnie ktoś poprawi w tym kodzie albo naprowadzi co jest źle i co zmienić.