private void button5_Click(object sender, EventArgs e) { if (openFileDialog1.FileName == "") { MessageBox.Show("Select an image first"); return; } BitmapW a = new BitmapW(openFileDialog1.FileName); pictureBox1.Image = a.GetBitmap(); //show the original image //apply effects BitmapW res = a.Clone(); //this will hold the final result //do some adjustments res = effects.brighten(res, 20); res = effects.saturate(res, -90); //add a purplish color BitmapW purple = a.Clone(); purple = effects.fill(purple, 34, 43, 109); res = layers.merge("softLight", res, purple); //do some more adjustments res = effects.gamma(res, -5); res = effects.contrast(res, 50); pictureBox2.Image = res.GetBitmap(); //show the resulting image }
private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.FileName == "") { MessageBox.Show("Select an image first"); return; } BitmapW a = new BitmapW(openFileDialog1.FileName); pictureBox1.Image = a.GetBitmap(); BitmapW layer1 = a.Clone(), layer2 = a.Clone(), layer3 = a.Clone(); //make three copies of the image l1,l2,l3 BitmapW res = a.Clone(); //this will hold the final result layer3 = effects.fill(layer3, 167, 118, 12); //layer 3 is a solid fill of this rgb color layer2 = effects.blur(layer2, "gaussian"); //layer2 is a blurred version of original image layer1 = effects.saturate(layer1, -50); //layer1 is a saturated version res = layers.merge("overlay", res, layer1); //merge layer1 onto original with "overlay" layer blending res = layers.merge("softLight", res, layer2); //now merge layer2 onto this, with "softlight" layer blending res = layers.merge("softLight", res, layer3); //now merge layer3 onto this, with "softlight" layer blending res = effects.saturate(res, -40); //apply -40 saturate effect on this now res = effects.contrast(res, 10); //apply 10 contrast pictureBox2.Image = res.GetBitmap(); //show the resulting image }
private void button6_Click(object sender, EventArgs e) { if (openFileDialog1.FileName == "") { MessageBox.Show("Select an image first"); return; } BitmapW a = new BitmapW(openFileDialog1.FileName); pictureBox1.Image = a.GetBitmap(); //show the original image //apply effects BitmapW layer1 = a.Clone(); //working layer 1 BitmapW res = a.Clone(); //this will hold the final result //do some adjustments res = effects.brighten(res, 10); res = effects.contrast(res, 30); //add a sepia softlight to the image layer1 = res.Clone(); layer1 = effects.sepia(layer1); layer1 = effects.vignette(layer1, 0, 0, 0); //some vignette too res = layers.merge("softLight", res, layer1); //add this layer to our image as softlight //desaturate a little res = effects.saturate(res, -30); //tadaaa pictureBox2.Image = res.GetBitmap(); //show the resulting image }
private void button7_Click(object sender, EventArgs e) { if (openFileDialog1.FileName == "") { MessageBox.Show("Select an image first"); return; } BitmapW a = new BitmapW(openFileDialog1.FileName); pictureBox1.Image = a.GetBitmap(); //show the original image //apply effect BitmapW res = a.Clone(); res = effects.saturate(res, -100); //grayscale it res = effects.contrast(res, 125); res = effects.noise(res, 3); res = effects.sepia(res); res = effects.adjust(res, 8, 2, 4); //tadaaa pictureBox2.Image = res.GetBitmap(); //show the resulting image }
private void button3_Click(object sender, EventArgs e) { if (openFileDialog1.FileName == "") { MessageBox.Show("Select an image first"); return; } BitmapW a = new BitmapW(openFileDialog1.FileName); pictureBox1.Image = a.GetBitmap(); BitmapW res = a.Clone(); //this will hold the final result res = effects.vignette(res, 0, 0, 0); pictureBox2.Image = res.GetBitmap(); //show the resulting image }
private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.FileName == "") { MessageBox.Show("Select an image first"); return; } BitmapW a = new BitmapW(openFileDialog1.FileName); pictureBox1.Image = a.GetBitmap(); BitmapW layer1 = a.Clone(), layer2 = a.Clone(), layer3 = a.Clone(); //make three copies of the image l1,l2,l3 BitmapW res = a.Clone(); //this will hold the final result layer3 = effects.fill(layer3, 167, 118, 12); //layer 3 is a solid fill of this rgb color layer2 = effects.blur(layer2, "gaussian"); //layer2 is a blurred version of original image layer1 = effects.saturate(layer1, -50); //layer1 is a saturated version res = layers.merge("overlay", res, layer1); //merge layer1 onto original with "overlay" layer blending res = layers.merge("softLight", res, layer2); //now merge layer2 onto this, with "softlight" layer blending res = layers.merge("softLight", res, layer3); //now merge layer3 onto this, with "softlight" layer blending res = effects.saturate(res,-40); //apply -40 saturate effect on this now res = effects.contrast(res, 10); //apply 10 contrast pictureBox2.Image = res.GetBitmap(); //show the resulting image }
public Blur CustomBlur = new Blur(); //the use in Form1.cs for example: "layer1 = effects.CustomBlur.Gaussain(layer1, 10);" BitmapW convolve(BitmapW image, float[,] kernel, int kw, int kh) { BitmapW temp = image.Clone(); // int kh = kernel; //int kw = kh; //kernel[0].Length / 2; int i = 0, j = 0, n = 0, m = 0, cr, cg, cb, ca, h = image.Height(), w = image.Width(); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { //kernel loop float r = 0, g = 0, b = 0, a = 0; for (n = -kh; n <= kh; n++) { for (m = -kw; m <= kw; m++) { if (i + n >= 0 && i + n < h) { if (j + m >= 0 && j + m < w) { float f = kernel[m + kw, n + kh]; if (f == 0) { continue; } Color colortemp = image.GetPixel(j + m, i + n); cr = colortemp.R; cg = colortemp.G; cb = colortemp.B; ca = colortemp.A; r += cr * f; g += cg * f; b += cb * f; a += ca * f; } } } } //kernel loop end temp.SetPixel(j, i, Color.FromArgb((int)Util.clamp(a, 0, 255), (int)Util.clamp(r, 0, 255), (int)Util.clamp(g, 0, 255), (int)Util.clamp(b, 0, 255))); } } return(temp); }
BitmapW convolve(BitmapW image, float[,] kernel, int kw, int kh) { BitmapW temp = image.Clone(); // int kh = kernel; //int kw = kh; //kernel[0].Length / 2; int i = 0, j = 0, n = 0, m = 0, cr, cg, cb, h = image.Height(), w = image.Width(); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { //kernel loop float r = 0, g = 0, b = 0; for (n = -kh; n <= kh; n++) { for (m = -kw; m <= kw; m++) { if (i + n >= 0 && i + n < h) { if (j + m >= 0 && j + m < w) { float f = kernel[m + kw, n + kh]; if (f == 0) { continue; } Color colortemp = image.GetPixel(j + m, i + n); cr = colortemp.R; cg = colortemp.G; cb = colortemp.B; r += cr * f; g += cg * f; b += cb * f; } } } } //kernel loop end temp.SetPixel(j, i, Color.FromArgb(255, (int)Util.clamp(r, 0, 255), (int)Util.clamp(g, 0, 255), (int)Util.clamp(b, 0, 255))); } } return temp; }
private BitmapW FastBoxBlur(BitmapW img, int radius) { int kSize = radius; if (kSize % 2 == 0) { kSize++; } BitmapW Hblur = img.Clone(); float Avg = (float)1 / kSize; for (int j = 0; j < img.Height(); j++) { float[] hSum = new float[] { 0f, 0f, 0f, 0f }; float[] iAvg = new float[] { 0f, 0f, 0f, 0f }; for (int x = 0; x < kSize; x++) { Color tmpColor = img.GetPixel(x, j); hSum[0] += tmpColor.A; hSum[1] += tmpColor.R; hSum[2] += tmpColor.G; hSum[3] += tmpColor.B; } iAvg[0] = hSum[0] * Avg; iAvg[1] = hSum[1] * Avg; iAvg[2] = hSum[2] * Avg; iAvg[3] = hSum[3] * Avg; for (int i = 0; i < img.Width(); i++) { if (i - kSize / 2 >= 0 && i + 1 + kSize / 2 < img.Width()) { Color tmp_pColor = img.GetPixel(i - kSize / 2, j); hSum[0] -= tmp_pColor.A; hSum[1] -= tmp_pColor.R; hSum[2] -= tmp_pColor.G; hSum[3] -= tmp_pColor.B; Color tmp_nColor = img.GetPixel(i + 1 + kSize / 2, j); hSum[0] += tmp_nColor.A; hSum[1] += tmp_nColor.R; hSum[2] += tmp_nColor.G; hSum[3] += tmp_nColor.B; // iAvg[0] = hSum[0] * Avg; iAvg[1] = hSum[1] * Avg; iAvg[2] = hSum[2] * Avg; iAvg[3] = hSum[3] * Avg; } Hblur.SetPixel(i, j, Color.FromArgb((int)iAvg[0], (int)iAvg[1], (int)iAvg[2], (int)iAvg[3])); } } BitmapW total = Hblur.Clone(); for (int i = 0; i < Hblur.Width(); i++) { float[] tSum = new float[] { 0f, 0f, 0f, 0f }; float[] iAvg = new float[] { 0f, 0f, 0f, 0f }; for (int y = 0; y < kSize; y++) { Color tmpColor = Hblur.GetPixel(i, y); tSum[0] += tmpColor.A; tSum[1] += tmpColor.R; tSum[2] += tmpColor.G; tSum[3] += tmpColor.B; } iAvg[0] = tSum[0] * Avg; iAvg[1] = tSum[1] * Avg; iAvg[2] = tSum[2] * Avg; iAvg[3] = tSum[3] * Avg; for (int j = 0; j < Hblur.Height(); j++) { if (j - kSize / 2 >= 0 && j + 1 + kSize / 2 < Hblur.Height()) { Color tmp_pColor = Hblur.GetPixel(i, j - kSize / 2); tSum[0] -= tmp_pColor.A; tSum[1] -= tmp_pColor.R; tSum[2] -= tmp_pColor.G; tSum[3] -= tmp_pColor.B; Color tmp_nColor = Hblur.GetPixel(i, j + 1 + kSize / 2); tSum[0] += tmp_nColor.A; tSum[1] += tmp_nColor.R; tSum[2] += tmp_nColor.G; tSum[3] += tmp_nColor.B; // iAvg[0] = tSum[0] * Avg; iAvg[1] = tSum[1] * Avg; iAvg[2] = tSum[2] * Avg; iAvg[3] = tSum[3] * Avg; } total.SetPixel(i, j, Color.FromArgb((int)iAvg[0], (int)iAvg[1], (int)iAvg[2], (int)iAvg[3])); } } return(total); }