- 最後登錄
- 2023-5-14
- 在線時間
- 0 小時
- 註冊時間
- 2009-5-20
- 閱讀權限
- 20
- 精華
- 0
- UID
- 6413828
- 帖子
- 275
- 積分
- 0 點
- 潛水值
- 16412 米
| 成為伊莉的版主,你將獲得更高級和無限的權限。把你感興趣的版面一步步地發展和豐盛,那種滿足感等著你來嚐嚐喔。 本帖最後由 KEIORL 於 2011-5-26 02:51 PM 編輯
很詭異 我包CODE好多次都沒辦法包=口=再失敗的話,請板主代勞吧...志不再得分在分享(笑- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Drawing.Imaging;
- namespace WindowsFormsApplication3
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- OpenFileDialog dlgFile = new OpenFileDialog();
- //dlgFile.InitialDirectory = ApplicationPath;
- dlgFile.Filter = "Images (*.bmp,*.jpg,*.jpeg)|*.bmp;*.jpg;*.jpeg";
- dlgFile.FilterIndex = 1;
- if (dlgFile.ShowDialog() == DialogResult.OK)
- {
- Bitmap bitmap = new Bitmap(dlgFile.FileName);
- pictureBox1.Image = bitmap;
- }
- }
- private void trackBar1_Scroll(object sender, EventArgs e)
- {
- label1.Text = trackBar1.Value.ToString();
- Bitmap bitmap = new Bitmap(pictureBox1.Image);
- for (int x = 0; x < bitmap.Width; x++)
- {
- for (int y = 0; y < bitmap.Height; y++)
- {
- Color color = bitmap.GetPixel(x, y);
- double r = color.R / 255.0;
- double g = color.G / 255.0;
- double b = color.B / 255.0;
- //RGB2HSB
- double CSon = (0.5 * (((r - g) + (r - b))));
- double CMon1 = Math.Pow(r - g, 2);
- double CMon2 = (r - b) * (g - b);
- double CMon = Math.Pow((CMon1 + CMon2), 0.5);
- double cos = Math.Acos((CSon / CMon)) * 180 / Math.PI;
- double h, s, i;
- if (b > g)
- h = 360 - cos;
- else
- h = cos;
- double s1 = (3.0 / (r + g + b));
- double s2 = Math.Min(Math.Min(r, g), b);
- s = 1 - s1 * s2;
- i = (r + b + g) / 3.0;
- i += trackBar1.Value / 255.0;
- //HSB2RGB
- double bb, rr, gg, AF, Son, Mon, AM;
- if (h >= 0 && h < 120)
- {
- Son = s * (Math.Cos(h / 180.0 * Math.PI));
- Mon = Math.Cos((60 - h) / 180.0 * Math.PI);
- AF = i * (1 - s);
- AM = i * (1 + (Son / Mon));
- bb = AF;
- rr = AM;
- gg = (3 * i) - (rr + bb);
- b = bb;
- r = rr;
- g = gg;
- }
- if (h >= 120 && h < 240)
- {
- h = h - 120;
- Son = s * (Math.Cos(h / 180.0 * Math.PI));
- Mon = Math.Cos((60 - h) / 180.0 * Math.PI);
- AF = i * (1 - s);
- AM = i * (1 + (Son / Mon));
- bb = AF;
- rr = AM;
- gg = (3 * i) - (rr + bb);
- b = gg;
- r = bb;
- g = rr;
- }
- if (h >= 240 && h < 360)
- {
- h = h - 240;
- Son = s * (Math.Cos(h / 180.0 * Math.PI));
- Mon = Math.Cos((60 - h) / 180.0 * Math.PI);
- AF = i * (1 - s);
- AM = i * (1 + (Son / Mon));
- bb = AF;
- rr = AM;
- gg = (3 * i) - (rr + bb);
- b = rr;
- r = gg;
- g = bb;
- }
- int R = (int)(r * 255);
- int G = (int)(g * 255);
- int B = (int)(b * 255);
- if (R > 255) R = 255;
- if (R < 0) R = 0;
- if (G > 255) G = 255;
- if (G < 0) G = 0;
- if (B > 255) B = 255;
- if (B < 0) B = 0;
- bitmap.SetPixel(x, y, Color.FromArgb(R, G, B));
- }
- }
- pictureBox2.Image = bitmap;
- }
- }
- }
複製代碼 ... |
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊 |