标签:
private void Form1_Load(object sender, EventArgs e) { img = pictureBox1.Image = Image.FromFile("8.jpg"); } Image img; private void button1_Click(object sender, EventArgs e) { using (Graphics g = pictureBox2.CreateGraphics()) { g.Clear(pictureBox2.BackColor); using (Image tmp = SetGamma(img.Clone() as Image, hsbRed.Value, hsbGreen.Value, hsbBlue.Value)) pictureBox2.Image = new Bitmap(tmp); } } /// <summary> /// 伽马曲线调整 /// </summary> /// <param name="img"></param> /// <param name="red"></param> /// <param name="green"></param> /// <param name="blue"></param> public Image SetGamma(Image img, double red, double green, double blue) { using (Bitmap tmp = img as Bitmap) { Color c; byte[] rG = CreateGammaArray(red); byte[] gG = CreateGammaArray(green); byte[] bG = CreateGammaArray(blue); for (int i = 0; i < tmp.Width; i++) { for (int j = 0; j < tmp.Height; j++) { c = tmp.GetPixel(i, j); tmp.SetPixel(i, j, Color.FromArgb(rG[c.R], gG[c.G], bG[c.B])); } } rG = gG = bG = null; return tmp.Clone() as Bitmap; } } /// <summary> /// 获取曲线数组 /// </summary> /// <param name="color">色彩</param> /// <returns>数组</returns> private byte[] CreateGammaArray(double color) { byte[] gammaArray = new byte[256]; for (int i = 1; i < 256; i++) gammaArray[i] = (byte)Math.Min(255, (int)((255.0 * Math.Pow(i / 255.0, 1.0 / color)) + 0.5)); return gammaArray; } private void hScrollBar1_Scroll(object sender, ScrollEventArgs e) { label5.Text = string.Format("Red={0},Green={1},Blue={2}", hsbRed.Value, hsbGreen.Value, hsbBlue.Value); button1.PerformClick(); } private void hsbGreen_Scroll(object sender, ScrollEventArgs e) { label5.Text = string.Format("Red={0},Green={1},Blue={2}", hsbRed.Value, hsbGreen.Value, hsbBlue.Value); button1.PerformClick(); } private void hsbBlue_Scroll(object sender, ScrollEventArgs e) { label5.Text = string.Format("Red={0},Green={1},Blue={2}", hsbRed.Value, hsbGreen.Value, hsbBlue.Value); button1.PerformClick(); }
标签:
原文地址:http://www.cnblogs.com/wjshan0808/p/4239494.html