public void DrawImage(Image image, Rectangle target, Rectangle source, GraphicsUnit gu) { APaint.Flags = (Android.Graphics.PaintFlags) 0; var sa = source.ToA(); var ta = target.ToA(); ACanvas.DrawBitmap((image as Bitmap).ABitmap, sa, ta, APaint); sa.Dispose(); ta.Dispose(); }
//Negativ private Android.Graphics.Bitmap createInverse(Android.Graphics.Bitmap src) { float[] colorMatrix_Negative = { -1.0f, 0, 0, 0, 255, //red 0, -1.0f, 0, 0, 255, //green 0, 0, -1.0f, 0, 255, //blue 0, 0, 0, 1.0f, 0 //alpha }; Android.Graphics.Paint MyPaint_Normal = new Android.Graphics.Paint(); Android.Graphics.Paint MyPaint_Negative = new Android.Graphics.Paint(); Android.Graphics.ColorFilter colorFilter_Negative = new Android.Graphics.ColorMatrixColorFilter(colorMatrix_Negative); MyPaint_Negative.SetColorFilter(colorFilter_Negative); Android.Graphics.Bitmap bitmap = Android.Graphics.Bitmap.CreateBitmap(src.Width, src.Height, Android.Graphics.Bitmap.Config.Argb8888); Android.Graphics.Canvas canvas = new Android.Graphics.Canvas(bitmap); MyPaint_Negative.SetColorFilter(colorFilter_Negative); canvas.DrawBitmap(src, 0, 0, MyPaint_Negative); return(bitmap); return(bitmap); }
//sepia si prietenii private Android.Graphics.Bitmap createSepia_and_RBG(Android.Graphics.Bitmap src, int choise) { Android.Graphics.ColorMatrix colorMatrix_Sepia = new Android.Graphics.ColorMatrix(); colorMatrix_Sepia.SetSaturation(0); Android.Graphics.ColorMatrix colorScale = new Android.Graphics.ColorMatrix(); if (choise == 1) { colorScale.SetScale(1, 1f, 0.7f, 1); //sepia } else if (choise == 2) { colorScale.SetScale(1, 1f, 2f, 1); //albastru } else if (choise == 3) { colorScale.SetScale(1, 2f, 1f, 1); //verde } else if (choise == 4) { colorScale.SetScale(2f, 1, 1f, 1); //rosu } //0.7 sepia ch =1 //0.4 ceva verziu //2 albastru fain //5 albastru neon colorMatrix_Sepia.PostConcat(colorScale); Android.Graphics.ColorFilter ColorFilter_Sepia = new Android.Graphics.ColorMatrixColorFilter( colorMatrix_Sepia); Android.Graphics.Bitmap bitmap = Android.Graphics.Bitmap.CreateBitmap(src.Width, src.Height, Android.Graphics.Bitmap.Config.Argb8888); Android.Graphics.Canvas canvas = new Android.Graphics.Canvas(bitmap); Android.Graphics.Paint paint = new Android.Graphics.Paint(); paint.SetColorFilter(ColorFilter_Sepia); canvas.DrawBitmap(src, 0, 0, paint); return(bitmap); }
protected override void OnDraw(Android.Graphics.Canvas canvas) { base.OnDraw(canvas); lock (this) { Image <Bgr, byte> image = _bgrBuffers.GetBuffer(0); if (image != null && !_imageSize.IsEmpty && canvas != null) { Stopwatch w = Stopwatch.StartNew(); if ((_bmpImage != null) && (!_imageSize.Equals(_bmpImage.Size))) { _bmpImage.Dispose(); _bmpImage = null; _bmp.Dispose(); _bmp = null; } if (_bmpImage == null) { _bmp = Android.Graphics.Bitmap.CreateBitmap(_imageSize.Width, _imageSize.Height, Android.Graphics.Bitmap.Config.Rgb565); _bmpImage = new BitmapRgb565Image(_bmp); } _bmpImage.ConvertFrom(image); canvas.DrawBitmap(_bmp, 0, 0, _paint); w.Stop(); _watch.Stop(); #if DEBUG canvas.DrawText(String.Format("{0:F2} FPS; {1}x{2}; Render Time: {3} ms", 1.0 / _watch.ElapsedMilliseconds * 1000, _imageSize.Width, _imageSize.Height, w.ElapsedMilliseconds), 20, 20, _paint); #endif _watch.Reset(); _watch.Start(); } } }
//Gray Filter public Android.Graphics.Bitmap toGrayscale(Android.Graphics.Bitmap bmpOriginal) { int width, height; height = bmpOriginal.Height; width = bmpOriginal.Width; Android.Graphics.Bitmap bmpGrayscale = Android.Graphics.Bitmap.CreateBitmap(width, height, Android.Graphics.Bitmap.Config.Argb8888); Android.Graphics.Canvas c = new Android.Graphics.Canvas(bmpGrayscale); Android.Graphics.Paint paint = new Android.Graphics.Paint(); Android.Graphics.ColorMatrix cm = new Android.Graphics.ColorMatrix(); cm.SetSaturation(0); Android.Graphics.ColorMatrixColorFilter f = new Android.Graphics.ColorMatrixColorFilter(cm); paint.SetColorFilter(f); c.DrawBitmap(bmpOriginal, 0, 0, paint); return(bmpGrayscale); }