protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); RequestWindowFeature(WindowFeatures.NoTitle); SetContentView(Resource.Layout.Main); _colorMatrix = new ColorMatrix(); _colorMatrixFilter = new ColorMatrixColorFilter(_colorMatrix); _paint = new Paint(); _paint.SetColorFilter(_colorMatrixFilter); var contrast = FindViewById<SeekBar>(Resource.Id.contrast); contrast.KeyProgressIncrement = 1; contrast.ProgressChanged += ContrastChanged; var brightness = FindViewById<SeekBar>(Resource.Id.brightness); brightness.KeyProgressIncrement = 1; brightness.ProgressChanged += BrightnessChanged; var saturation = FindViewById<SeekBar>(Resource.Id.saturation); saturation.KeyProgressIncrement = 1; saturation.ProgressChanged += SaturationChanged; var imageSelector = FindViewById<Button>(Resource.Id.selectImage); imageSelector.Click += ImagesSelectorClick; _imageViewer = FindViewById<ImageView>(Resource.Id.imageViewer); }
public static ColorFilter getColorFilter(int color) { ColorMatrixColorFilter colorFilter; int red = (color & 0xFF0000) / 0xFFFF; int green = (color & 0xFF00) / 0xFF; int blue = color & 0xFF; float[] matrix = { 0, 0, 0, 0, red , 0, 0, 0, 0, green , 0, 0, 0, 0, blue , 0, 0, 0, 1, 0 }; colorFilter = new ColorMatrixColorFilter(matrix); return colorFilter; }
public static Bitmap ToGreyScale(this Bitmap bmp) { if (bmp == null) return null; var height = bmp.Height; var width = bmp.Width; var bmpGrayscale = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); var canvas = new Canvas(bmpGrayscale); var paint = new Paint(); var cm = new ColorMatrix(); cm.SetSaturation(0); var filter = new ColorMatrixColorFilter(cm); paint.SetColorFilter(filter); canvas.DrawBitmap(bmp, 0, 0, paint); return bmpGrayscale; }
protected override void OnElementChanged(ElementChangedEventArgs<Image> e) { base.OnElementChanged(e); if (Element == null) { return; } var matrixColor = new ColorMatrix(); filterColor = new ColorMatrixColorFilter(matrixColor); var matrixGray = new ColorMatrix(); matrixGray.SetSaturation(0); filterGray = new ColorMatrixColorFilter(matrixGray); }
protected override void OnDraw(Canvas canvas) { if (_image != null && _filter != null) { var cFilter = new ColorMatrixColorFilter (_filter); Paint paint = new Paint (); paint.SetColorFilter (cFilter); Matrix matrix = new Matrix (); canvas.Save (); float horizotalScale = (Right - Left) / (float)_image.Width; float verticalScale = (Bottom - Top) / (float)_image.Height; float scale = horizotalScale < verticalScale ? horizotalScale : verticalScale; matrix.SetScale (scale,scale); canvas.DrawBitmap (_image, matrix, paint); canvas.Restore (); } }
public Android.Graphics.Bitmap ToGrayscale(Android.Graphics.Bitmap bmpOriginal) { int width, height; height = bmpOriginal.Height; width = bmpOriginal.Width; float[] mat = new float[] { 0.3f, 0.59f, 0.11f, 0, 0, 0.3f, 0.59f, 0.11f, 0, 0, 0.3f, 0.59f, 0.11f, 0, 0, 0, 0, 0, 1, 0, }; Android.Graphics.Bitmap bmpGrayscale = Android.Graphics.Bitmap.CreateBitmap(width, height, Android.Graphics.Bitmap.Config.Argb8888); GC.Collect(); Android.Graphics.Canvas c = new Android.Graphics.Canvas(bmpGrayscale); Android.Graphics.ColorMatrixColorFilter filter = new Android.Graphics.ColorMatrixColorFilter(mat); Android.Graphics.Paint paint = new Android.Graphics.Paint(); paint.SetColorFilter(filter); c.DrawBitmap(bmpOriginal, 0, 0, paint); return(bmpGrayscale); }
public Bitmap Transform(Bitmap source) { Bitmap result = Bitmap.CreateBitmap(source.Width, source.Height, source.GetConfig()); Bitmap noise; try { noise = picasso.Load(Resource.Drawable.noise).Get(); } catch (Exception) { throw new Exception("Failed to apply transformation! Missing resource."); } BitmapShader shader = new BitmapShader(noise, Shader.TileMode.Repeat, Shader.TileMode.Repeat); ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.SetSaturation(0); ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix); Paint paint = new Paint(PaintFlags.AntiAlias); paint.SetColorFilter(filter); Canvas canvas = new Canvas(result); canvas.DrawBitmap(source, 0, 0, paint); paint.SetColorFilter(null); paint.SetShader(shader); paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.Multiply)); canvas.DrawRect(0, 0, canvas.Width, canvas.Height, paint); source.Recycle(); noise.Recycle(); return result; }
void UpdateImage() { _colorMatrixFilter = new ColorMatrixColorFilter(_colorMatrix); _paint.SetColorFilter(_colorMatrixFilter); SetBitmapToImageViewer(); }
public ColorFilter(View parent, ColorMatrix cm) { CFilter = new ColorMatrixColorFilter(cm); Parent = parent; }
private ImageView GetBrushImageWithColor(ImageView brushImage, Android.Graphics.Color color) { ImageView toReturn = new ImageView (context); using (Bitmap sourceBitmap = brushImage.DrawingCache) { if (sourceBitmap != null) { float R = (float)color.R; float G = (float)color.G; float B = (float)color.B; float[] colorTransform = { R / 255f ,0 ,0 ,0, 0, // R color 0, G / 255f , 0 ,0 ,0 // G color ,0 ,0 , B / 255f, 0, 0 // B color ,0 ,0 ,0 ,1f ,0f }; ColorMatrix colorMatrix = new ColorMatrix (); colorMatrix.SetSaturation (0f); //Remove Colour colorMatrix.Set (colorTransform); ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter (colorMatrix); Paint paint = new Paint (); paint.SetColorFilter (colorFilter); Bitmap mutableBitmap = sourceBitmap.Copy (Bitmap.Config.Argb8888, true); toReturn.SetImageBitmap (mutableBitmap); Canvas canvas = new Canvas (mutableBitmap); canvas.DrawBitmap (mutableBitmap, 0, 0, paint); } } return toReturn; }