public static Bitmap ToSepia(Bitmap source) { using (ColorMatrix saturation = new ColorMatrix()) using (ColorMatrix rgbFilter = new ColorMatrix()) { saturation.SetSaturation(0f); rgbFilter.SetScale(1.0f, 0.95f, 0.82f, 1.0f); saturation.SetConcat(rgbFilter, saturation); return(ColorSpaceTransformation.ToColorSpace(source, saturation)); } }
void UpdateColorMatrix(float[][] rgbawMatrix) { var rOffset = rgbawMatrix[0][4]; var gOffset = rgbawMatrix[1][4]; var bOffset = rgbawMatrix[2][4]; var aOffset = rgbawMatrix[3][4]; _colorMatrix.SetScale(rOffset, gOffset, bOffset, aOffset); var transposed = GetAndroidMatrix(rgbawMatrix); _colorMatrix.Set(transposed); }
public byte[] Sepia(byte[] image) { Bitmap bmpOriginal = ByteToBitmap(image); int width, height, r, g, b, c, gry; height = bmpOriginal.Height; width = bmpOriginal.Width; int depth = 20; Bitmap bmpSephia = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(bmpSephia); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.SetScale(.3f, .3f, .3f, 1.0f); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.SetColorFilter(f); canvas.DrawBitmap(bmpOriginal, 0, 0, paint); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { c = bmpOriginal.GetPixel(x, y); r = Android.Graphics.Color.GetRedComponent(c); g = Android.Graphics.Color.GetGreenComponent(c); b = Android.Graphics.Color.GetBlueComponent(c); gry = (r + g + b) / 3; r = g = b = gry; r = r + (depth * 2); g = g + depth; if (r > 255) { r = 255; } if (g > 255) { g = 255; } bmpSephia.SetPixel(x, y, Android.Graphics.Color.Rgb(r, g, b)); } } byte[] sepiaimage = BitmaptoByte(bmpSephia); return(sepiaimage); }