/// <summary> /// Adjusts the blue levels of the image /// </summary> /// <param name="blue">Amount to Adjust the Blue Values</param> /// <param name="iE">Image to modify</param> private void AdjustBlue(int blue, imageEdit iE) { int value = 0; for (int i = 0; i < iE.getHeight(); i++) for (int j = 0; j < iE.getWidth(); j++) { //Blue value = data[i, j, 2] + blue; if (value > 255) value = 255; if (value < 0) value = 0; iE.image[i, j, 2] = (byte)value; } }
/// <summary> /// Copy Constructor /// </summary> /// <param name="pic">imageEdit</param> public imageEdit(imageEdit pic) { image = new byte[pic.getHeight(), pic.getWidth(), 3]; iH = pic.getHeight(); iW = pic.getWidth(); for (int i = 0; i < iH; i++) for (int j = 0; j < iW; j++) { this.image[i, j, 0] = pic.image[i, j, 0]; this.image[i, j, 1] = pic.image[i, j, 1]; this.image[i, j, 2] = pic.image[i, j, 2]; this.image[i, j, 3] = pic.image[i, j, 3]; } }
/// <summary> /// Adjusts the Color levels of the image /// </summary> /// <param name="red">Amount to Adjust the Red Values</param> /// <param name="green">Amount to Adjust the Green Values</param> /// <param name="blue">Amount to Adjust the Blue Values</param> /// <param name="iE">Image to modify</param> private void AdjustColor(int red, int green, int blue, imageEdit iE) { int value = 0; for (int i = 0; i < iE.getHeight(); i++) for (int j = 0; j < iE.getWidth(); j++) { //Red value = data[i, j, 0] + red; if (value > 255) value = 255; if (value < 0) value = 0; iE.image[i, j, 0] = (byte)value; //Green value = data[i, j, 1] + green; if (value > 255) value = 255; if (value < 0) value = 0; iE.image[i, j, 1] = (byte)value; //Blue value = data[i, j, 2] + blue; if (value > 255) value = 255; if (value < 0) value = 0; iE.image[i, j, 2] = (byte)value; } }
/// <summary> /// Lightens or Darkens an image /// </summary> /// <param name="br">Value of new Brightness</param> /// <param name="iE">imageEdit to be modified</param> public void Brightness(int br, imageEdit iE) { int nVal = 0; for (int i = 0; i < ch.pic.getHeight(); i++) for (int j = 0; j < ch.pic.getWidth(); j++) { //Red nVal = (data[i, j, 0] + br); if (nVal < 0) nVal = 0; if (nVal > 255) nVal = 255; iE.image[i, j, 0] = (byte)nVal; //Green nVal = (data[i, j, 1] + br); if (nVal < 0) nVal = 0; if (nVal > 255) nVal = 255; iE.image[i, j, 1] = (byte)nVal; //Blue nVal = (data[i, j, 2] + br); if (nVal < 0) nVal = 0; if (nVal > 255) nVal = 255; iE.image[i, j, 2] = (byte)nVal; } }
/// <summary> /// Corrects the Gamma intensity of the image /// </summary> /// <param name="gam">Gamma modifier</param> /// <param name="iE">imageEdit to be modified</param> private void GammaCorrection(double gam, imageEdit iE) { for (int i = 0; i < iE.getHeight(); i++) for (int j = 0; j < iE.getWidth(); j++) { //Red iE.image[i, j, 0] = (byte)(255 * Math.Pow(((double)data[i, j, 0] / 255.0), gam)); //Green iE.image[i, j, 1] = (byte)(255 * Math.Pow(((double)data[i, j, 1] / 255.0), gam)); //Blue iE.image[i, j, 2] = (byte)(255 * Math.Pow(((double)data[i, j, 2] / 255.0), gam)); } }
/// <summary> /// Increases or lowers contrast of the image /// </summary> /// <param name="con">Contrast modifier</param> /// <param name="iE">imageEdit to be modified</param> public void Contrast(int con, imageEdit iE) { double pixel = 0, contrast = (100.0 + con) / 100.0; contrast *= contrast; byte red, green, blue; for (int i = 0; i < ch.pic.getHeight(); i++) for (int j = 0; j < ch.pic.getWidth(); j++) { red = data[i, j, 0]; green = data[i, j, 1]; blue = data[i, j, 2]; //Red pixel = red / 255.0; pixel -= 0.5; pixel *= contrast; pixel += 0.5; pixel *= 255; if (pixel < 0) pixel = 0; if (pixel > 255) pixel = 255; iE.image[i, j, 0] = (byte)pixel; //Green pixel = green / 255.0; pixel -= 0.5; pixel *= contrast; pixel += 0.5; pixel *= 255; if (pixel < 0) pixel = 0; if (pixel > 255) pixel = 255; iE.image[i, j, 1] = (byte)pixel; //Blue pixel = blue / 255.0; pixel -= 0.5; pixel *= contrast; pixel += 0.5; pixel *= 255; if (pixel < 0) pixel = 0; if (pixel > 255) pixel = 255; iE.image[i, j, 2] = (byte)pixel; } }
/// <summary> /// Loads an Image into b. (saves original in o). /// </summary> /// <param name="f">The filename to load.</param> public void LoadImage(string f) { if (b != null) b.Dispose(); if (o != null) b.Dispose(); b = (Bitmap)Image.FromFile(f); o = (Bitmap)b.Clone(new Rectangle(0, 0, b.Width, b.Height), b.PixelFormat); if (pic == null) pic = new imageEdit(b); else { pic = null; pic = new imageEdit(b); } }
/// <summary> /// Adjusts the red levels of the image /// </summary> /// <param name="red">Amount to Adjust the Red Values</param> /// <param name="iE">Image to modify</param> private void AdjustRed(int red, imageEdit iE) { int value = 0; for (int i = 0; i < iE.getHeight(); i++) for (int j = 0; j < iE.getWidth(); j++) { //Red value = data[i, j, 0] + red; if (value > 255) value = 255; if (value < 0) value = 0; iE.image[i, j, 0] = (byte)value; } }
/// <summary> /// Adjusts the green levels of the image /// </summary> /// <param name="green">Amount to Adjust the Green Values</param> /// <param name="iE">Image to modify</param> private void AdjustGreen(int green, imageEdit iE) { int value = 0; for (int i = 0; i < iE.getHeight(); i++) for (int j = 0; j < iE.getWidth(); j++) { //Green value = data[i, j, 1] + green; if (value > 255) value = 255; if (value < 0) value = 0; iE.image[i, j, 1] = (byte)value; } }