Exemplo n.º 1
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);
			}
		}
        protected override void OnCreate(Bundle bundle)
        {
            _bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.image_for_cropping);
            base.OnCreate (bundle);

            _mainLayout = new MainLayout (this);
            _mainLayout.ImageView.SetBitmap (_bitmap);

            var filter = new ColorMatrix ();
            filter.SetScale (1, 1, 1, 1);
            _mainLayout.ImageView.SetFilter (filter);

            SetContentView (_mainLayout);

            _mainLayout.RedSeek.Progress = _mainLayout.GreenSeek.Progress  = _mainLayout.BlueSeek.Progress = _mainLayout.AlphaSeek.Progress = 50;

            _mainLayout.RedSeek.StopTrackingTouch += OnChangeSeek;
            _mainLayout.GreenSeek.StopTrackingTouch += OnChangeSeek;
            _mainLayout.BlueSeek.StopTrackingTouch += OnChangeSeek;
            _mainLayout.AlphaSeek.StopTrackingTouch += OnChangeSeek;
            _mainLayout.LoadImage.Click += LoadImage;
        }
        private void OnChangeSeek(object sender, Android.Widget.SeekBar.StopTrackingTouchEventArgs e)
        {
            float scailR = 2f * _mainLayout.RedSeek.Progress / 100F;
            float scailG = 2f * _mainLayout.GreenSeek.Progress / 100F;
            float scailB = 2f * _mainLayout.BlueSeek.Progress / 100F;
            float scailA = 2f * _mainLayout.AlphaSeek.Progress / 100F;

            var filter = new ColorMatrix ();
            filter.SetScale (scailR, scailG, scailB, scailA);

            _mainLayout.ImageView.SetFilter (filter);

            _mainLayout.TextView.Text = "R: " + scailR + " | G: " + scailG + " | B : " + scailB + " | A: " + scailA;
        }