public static Bitmap addition(Bitmap input, Bitmap overlay) { if (input.Width == overlay.Width && input.Height == overlay.Height) { raw_image.imagebits sourceImg = input.toImageBits(); raw_image.imagebits overlayImg = overlay.toImageBits(); for (int i = 0; i < sourceImg.b.Length; i++) { int alphaValue = overlayImg.a[i]; float percent = (float)alphaValue / 255f; sourceImg.b[i] = (byte)Convert.ToInt32(sourceImg.b[i] + (overlayImg.b[i] * percent)).Clamp(0, 255); sourceImg.g[i] = (byte)Convert.ToInt32(sourceImg.g[i] + (overlayImg.g[i] * percent)).Clamp(0, 255); sourceImg.r[i] = (byte)Convert.ToInt32(sourceImg.r[i] + (overlayImg.r[i] * percent)).Clamp(0, 255); } return(sourceImg.toBitMap()); } else { //throw new ArgumentException("Images were not the same dimentions, cannot operate", "overlay"); return(input); } }
public static Bitmap brightness(Bitmap input, float value) { raw_image.imagebits sourceImg = input.toImageBits(); for (int i = 0; i < sourceImg.b.Length; i++) { sourceImg.b[i] = (byte)Convert.ToInt32(sourceImg.b[i] * value).Clamp(0, 255); sourceImg.g[i] = (byte)Convert.ToInt32(sourceImg.g[i] * value).Clamp(0, 255); sourceImg.r[i] = (byte)Convert.ToInt32(sourceImg.r[i] * value).Clamp(0, 255); } return(sourceImg.toBitMap()); }
public Bitmap applyToImage(Bitmap image) { raw_image.imagebits allbits = image.toImageBits(); int gradLen = gradientBits.a.Length; for (int i = 0; i < allbits.r.Length; i++) { int average = (allbits.r[i] + allbits.g[i] + allbits.b[i]) / 3; allbits.r[i] = gradientBits.r[average.remap(0, 255, 0, gradLen)]; allbits.g[i] = gradientBits.g[average.remap(0, 255, 0, gradLen)]; allbits.b[i] = gradientBits.b[average.remap(0, 255, 0, gradLen)]; } return(allbits.toBitMap()); }
public static Bitmap greyScaleAverage(this Bitmap input) { raw_image.imagebits source = input.toImageBits(); for (int i = 0; i < source.b.Length; i++) { int total = 0; total += source.b[i]; total += source.g[i]; total += source.r[i]; int newVal = total / 3; source.b[i] = (byte)newVal; source.g[i] = (byte)newVal; source.r[i] = (byte)newVal; } return(source.toBitMap()); }
/// <summary> /// Loads an image gradient from disk /// </summary> /// <param name="path">The path to load image gradient from</param> public image_gradient(string path) { Bitmap source = new Bitmap(path); gradientBits = source.toImageBits(); }