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);
        }
Esempio n. 2
0
 public static Bitmap ToGrayscale(Bitmap source)
 {
     using (var colorMatrix = new ColorMatrix())
     {
         colorMatrix.SetSaturation(0f);
         return(ColorSpaceTransformation.ToColorSpace(source, colorMatrix));
     }
 }
Esempio n. 3
0
 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 SaturationChanged(object sender, SeekBar.ProgressChangedEventArgs e)
        {
            if (!_imageSelected)
            {
                return;
            }

            float value = e.Progress / 100f;

            _colorMatrix.SetSaturation(value);
            UpdateImage();
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Image> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                ColorMatrix matrix = new ColorMatrix();
                matrix.SetSaturation(0);
                ColorMatrixColorFilter cf = new ColorMatrixColorFilter(matrix);
                Control.SetColorFilter(cf);
                Control.ImageAlpha = 128;
            }
        }
Esempio n. 6
0
        // Fill in the contents of the photo card (invoked by the layout manager):
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            RecyclerViewHolder vh = holder as RecyclerViewHolder;

            context = Application.Context;
            // Set the ImageView and TextView in this ViewHolder's CardView
            // from this position in the photo album:
            vh.LevelNameTextView.Text       = levels[position].LevelName;
            vh.LevelNumberTextView.Text     = levels[position].Number.ToString();
            vh.LevelScoreTextView.Text      = levels[position].LevelScoreEarned.ToString();
            vh.LevelTotalScoreTextView.Text = levels[position].LevelTotalScore.ToString();

            vh.MapImageView.SetImageResource(levels[position].Map);
            vh.LeftFlagImageView1.SetImageResource(levels[position].LeftFlag1);
            vh.LeftFlagImageView2.SetImageResource(levels[position].LeftFlag2);
            vh.LeftFlagImageView3.SetImageResource(levels[position].LeftFlag3);
            vh.RightFlagImageView1.SetImageResource(levels[position].RightFlag1);
            vh.RightFlagImageView2.SetImageResource(levels[position].RightFlag2);
            vh.RightFlagImageView3.SetImageResource(levels[position].RightFlag3);
            vh.VehicleTypeImageView1.SetImageResource(levels[position].VehicleType1);
            vh.VehicleTypeImageView2.SetImageResource(levels[position].VehicleType2);

            ColorMatrix matrix = new ColorMatrix();

            matrix.SetSaturation(0);
            ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);

            #region BWImage
            if (levels[position].LevelUnlocked)
            {
                //
            }
            else
            {
                vh.MapImageView.SetColorFilter(filter);
                vh.LeftFlagImageView1.SetColorFilter(filter);
                vh.LeftFlagImageView2.SetColorFilter(filter);
                vh.LeftFlagImageView3.SetColorFilter(filter);
                vh.RightFlagImageView1.SetColorFilter(filter);
                vh.RightFlagImageView2.SetColorFilter(filter);
                vh.RightFlagImageView3.SetColorFilter(filter);
                vh.VehicleTypeImageView1.SetColorFilter(filter);
                vh.VehicleTypeImageView2.SetColorFilter(filter);
                vh.LevelNameLinear.SetBackgroundResource(Resource.Drawable._MMTopLevelGray);
                vh.LevelScoreTextView.SetTextColor(Color.Gray);
                vh.LevelTotalScoreTextView.SetTextColor(Color.Gray);
                vh.LevelScoreDividerTextView.SetTextColor(Color.Gray);
            }

            #endregion
        }
Esempio n. 7
0
        //Metoda pro změnu saturace. Zde nemusíme vytvářet matici, ale třída ColorMatrix má vlastní meotdu pro změnu saturace, do které se nahraje pouze hodnota.
        public Bitmap SaturationChanged(Bitmap oldBtm, float value)
        {
            newBtm = Bitmap.CreateBitmap(oldBtm.Width, oldBtm.Height, oldBtm.GetConfig());

            clrMatrix = new ColorMatrix();
            clrMatrix.SetSaturation(value);

            imgMtrxFilter = new ColorMatrixColorFilter(clrMatrix);
            paint         = new Paint();
            paint.SetColorFilter(imgMtrxFilter);
            canvas = new Canvas(newBtm);

            canvas.DrawBitmap(oldBtm, new Matrix(), paint);
            return(newBtm);
        }
Esempio n. 8
0
        public override Bitmap Operations(Bitmap source, Bitmap result)
        {
            Canvas      canvas     = new Canvas(result);
            ColorMatrix saturation = new ColorMatrix();

            saturation.SetSaturation(0f);
            Paint paint = new Paint();

            paint.SetColorFilter(new ColorMatrixColorFilter(saturation));
            canvas.DrawBitmap(source, 0, 0, paint);

            source.Recycle();

            return(result);
        }
Esempio n. 9
0
        public Bitmap ToGrayscale(Bitmap bmpOriginal)
        {
            var height = bmpOriginal.Height;
            var width  = bmpOriginal.Width;

            var bmpGrayscale = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
            var c            = new Canvas(bmpGrayscale);
            var paint        = new Paint();
            var cm           = new ColorMatrix();

            cm.SetSaturation(0);
            var f = new ColorMatrixColorFilter(cm);

            paint.SetColorFilter(f);
            c.DrawBitmap(bmpOriginal, 0, 0, paint);
            return(bmpGrayscale);
        }
Esempio n. 10
0
 public void OnAnimationUpdate(ValueAnimator animation)
 {
     if (animation == animationSat)
     {
         matrix.SetSaturation((float)animation.AnimatedValue);
         saturation = (float)animation.AnimatedValue;
         ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
         mImage.SetColorFilter(filter);
     }
     else if (animation == animationZoomIn)
     {
         Control.ScaleX = (float)animation.AnimatedValue;
         Control.ScaleY = (float)animation.AnimatedValue;
         zoom           = (float)animation.AnimatedValue;
     }
     Control.SetImageDrawable(mImage);
 }
        public Bitmap Transform(Bitmap source)
        {
            int width  = source.Width;
            int height = source.Height;

            Bitmap bitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);

            Canvas      canvas     = new Canvas(bitmap);
            ColorMatrix saturation = new ColorMatrix();

            saturation.SetSaturation(0f);
            Paint paint = new Paint();

            paint.SetColorFilter(new ColorMatrixColorFilter(saturation));
            canvas.DrawBitmap(source, 0, 0, paint);
            source.Recycle();
            return(bitmap);
        }
Esempio n. 12
0
        // 转成灰度图
        public static Bitmap toGrayscale(Bitmap bmpOriginal)
        {
            int width, height;

            height = bmpOriginal.Height;
            width  = bmpOriginal.Width;
            Bitmap bmpGrayscale = Bitmap.CreateBitmap(width, height,
                                                      Config.Argb8888);
            Canvas      c     = new Canvas(bmpGrayscale);
            Paint       paint = new Paint();
            ColorMatrix cm    = new ColorMatrix();

            cm.SetSaturation(0);
            ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);

            paint.SetColorFilter(f);
            c.DrawBitmap(bmpOriginal, 0, 0, paint);
            return(bmpGrayscale);
        }
Esempio n. 13
0
        public Android.Graphics.Bitmap ToGrayScale(Android.Graphics.Bitmap image)
        {
            int width, height;

            height = image.Height;
            width  = image.Width;

            Android.Graphics.Bitmap bmpGrayscale = Android.Graphics.Bitmap.CreateBitmap(width, height, Android.Graphics.Bitmap.Config.Argb8888);
            Canvas      c     = new Canvas(bmpGrayscale);
            Paint       paint = new Paint();
            ColorMatrix cm    = new ColorMatrix();

            cm.SetSaturation(0);
            ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);

            paint.SetColorFilter(f);
            c.DrawBitmap(image, 0, 0, paint);
            return(bmpGrayscale);
        }
Esempio n. 14
0
        public byte[] ResizeImage(byte[] imageData, float width, float height, int quality)
        {
            // Load the bitmap
            Bitmap originalImage = BitmapFactory.DecodeByteArray(imageData, 0, imageData.Length);

            float oldWidth    = (float)originalImage.Width;
            float oldHeight   = (float)originalImage.Height;
            float scaleFactor = 0f;

            if (oldWidth > oldHeight)
            {
                scaleFactor = width / oldWidth;
            }
            else
            {
                scaleFactor = height / oldHeight;
            }

            float newHeight = oldHeight * scaleFactor;
            float newWidth  = oldWidth * scaleFactor;

            Bitmap resizedImage = Bitmap.CreateScaledBitmap(originalImage, (int)newWidth, (int)newHeight, false);


            int scaled_width, scaled_height;

            scaled_height = resizedImage.Height;
            scaled_width  = resizedImage.Width;

            Paint       paint = new Paint();
            ColorMatrix cm    = new ColorMatrix();

            cm.SetSaturation(0);
            ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);

            paint.SetColorFilter(f);

            using (MemoryStream ms = new MemoryStream())
            {
                resizedImage.Compress(Bitmap.CompressFormat.Jpeg, quality, ms);
                return(ms.ToArray());
            }
        }
        Bitmap ApplyBlackAndWhite(Bitmap src)
        {
            Bitmap bw = src.Copy();
            //Bitmap bw= Bitmap.CreateBitmap(c);
            //using (Bitmap bw = Bitmap.CreateBitmap(src))

            var canvas = new Canvas(bw);
            var ma     = new ColorMatrix();

            ma.SetSaturation(0);

            var paint = new Paint();

            paint.SetColorFilter(new ColorMatrixColorFilter(ma));

            canvas.DrawBitmap(bw, 0, 0, paint);


            return(bw);
        }
Esempio n. 16
0
        public static Bitmap toGrayScale(this string fileName)
        {
            BitmapFactory.Options options = new BitmapFactory.Options {
                InPreferredConfig = Bitmap.Config.Argb8888
            };
            Bitmap originalBitmap = BitmapFactory.DecodeFile(fileName, options);

            Bitmap      grayBitmap  = Bitmap.CreateBitmap(options.OutWidth, options.OutHeight, originalBitmap.GetConfig());
            Canvas      canvas      = new Canvas(grayBitmap);
            Paint       paint       = new Paint();
            ColorMatrix colorMatrix = new ColorMatrix();

            colorMatrix.SetSaturation(0);
            ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);

            paint.SetColorFilter(colorFilter);
            canvas.DrawBitmap(originalBitmap, 0, 0, paint);

            return(grayBitmap);
        }
Esempio n. 17
0
        public static Bitmap Grayscale_ColorMatrixColorFilter(Bitmap src)
        {
            int width  = src.Width;
            int height = src.Height;

            Bitmap dest = Bitmap.CreateBitmap(width, height, Bitmap.Config.Rgb565);

            Canvas canvas = new Canvas(dest);

            Paint       paint       = new Paint();
            ColorMatrix colorMatrix = new ColorMatrix();

            colorMatrix.SetSaturation(0); //value of 0 maps the color to gray-scale
            ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);

            paint.SetColorFilter(filter);
            canvas.DrawBitmap(src, 0, 0, paint);

            return(dest);
        }
Esempio n. 18
0
        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);
        }
        Bitmap ApplySaturation(Bitmap src, int value)
        {
            var bm      = src.Copy();
            var f_value = (float)(value / 100.0);

            //var w = c.Width;
            //var h = c.Height;

            //var bm = Bitmap.CreateBitmap(w, h, Bitmap.Config.Argb8888);
            var canvasResult = new Canvas(bm);
            var paint        = new Paint();
            var colorMatrix  = new ColorMatrix();

            colorMatrix.SetSaturation(f_value);
            var filter = new ColorMatrixColorFilter(colorMatrix);

            paint.SetColorFilter(filter);
            canvasResult.DrawBitmap(bm, 0, 0, paint);

            return(bm);
        }
Esempio n. 20
0
        public ColorMatrix Create()
        {
            ColorMatrix cm = new ColorMatrix(new float[]
            {
                _contrast, 0, 0, 0, _brightness,
                0, _contrast, 0, 0, _brightness,
                0, 0, _contrast, 0, _brightness,
                0, 0, 0, _alpha, 0
            });

            AdjustHue(cm, _hue);
            //if (_saturation < 0.99f)
            {
                var cm2 = new ColorMatrix();
                cm2.SetSaturation(_saturation);
                cm.PostConcat(cm2);
                //cm.SetSaturation(_saturation);
            }

            return(cm);
        }
        public IEditableImage ToMonochrome()
        {
            Bitmap      bmpMonochrome = Bitmap.CreateBitmap(_image.Width, _image.Height, Bitmap.Config.Rgb565);
            Canvas      canvas        = new Canvas(bmpMonochrome);
            ColorMatrix ma            = new ColorMatrix();

            ma.SetSaturation(0);
            Paint paint = new Paint();

            paint.SetColorFilter(new ColorMatrixColorFilter(ma));
            canvas.DrawBitmap(_image, 0, 0, paint);

            _image.Recycle();
            _image.Dispose();
            _image        = bmpMonochrome;
            bmpMonochrome = null;

            canvas.Dispose();
            ma.Dispose();
            paint.Dispose();

            return(this);
        }