Exemple #1
1
 public static Bitmap ScaleUpBitmap(Bitmap originalImage, int wantedWidth, int wantedHeight)
 {
     Bitmap output = Bitmap.CreateBitmap(wantedWidth, wantedHeight, Bitmap.Config.Argb8888);
     Canvas canvas = new Canvas(output);
     Matrix m = new Matrix();
     m.SetScale((float)wantedWidth / originalImage.Width, (float)wantedHeight / originalImage.Height);
     canvas.DrawBitmap(originalImage, m, new Paint());
     canvas.Dispose ();
     originalImage.Dispose ();
     return output;
 }
			protected override void OnDraw (Canvas canvas)
			{
				canvas.DrawColor (Color.White);

				Paint p = new Paint ();
				float y = 10;

				p.Color = Color.Red;
				canvas.DrawBitmap (mBitmap, 10, y, p);
				y += mBitmap.Height + 10;
				canvas.DrawBitmap (mBitmap2, 10, y, p);
				y += mBitmap2.Height + 10;
				p.SetShader (mShader);
				canvas.DrawBitmap (mBitmap3, 10, y, p);
			}
Exemple #3
0
		protected override void OnDraw(Canvas canvas) {
			base.OnDraw (canvas);
			if (mBlurredView != null) {
				if (prepare()) {
					// If the background of the blurred view is a color drawable, we use it to clear
					// the blurring canvas, which ensures that edges of the child views are blurred
					// as well; otherwise we clear the blurring canvas with a transparent color.
					if (mBlurredView.Background != null && mBlurredView.Background is ColorDrawable){
						mBitmapToBlur.EraseColor(((ColorDrawable) mBlurredView.Background).Color);
					}else {
						mBitmapToBlur.EraseColor(Color.Transparent);
					}

					mBlurredView.Draw(mBlurringCanvas);
					blur();

					canvas.Save();
					canvas.Translate(mBlurredView.GetX() - GetX(), mBlurredView.GetY() - GetY());
					canvas.Scale(mDownsampleFactor, mDownsampleFactor);
					canvas.DrawBitmap(mBlurredBitmap, 0, 0, null);
					canvas.Restore();
				}
				canvas.DrawColor(mOverlayColor);
			}
		}
Exemple #4
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            base.OnDraw(canvas);

            if (bitmap == null || bitmap.Width != canvas.Width || bitmap.Height != canvas.Height)
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }

                bitmap = Bitmap.CreateBitmap(canvas.Width, canvas.Height, Bitmap.Config.Argb8888);
            }

            try
            {
                using (var surface = SKSurface.Create(canvas.Width, canvas.Height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, bitmap.LockPixels(), canvas.Width * 4)) {
                    var skcanvas = surface.Canvas;
                    skcanvas.Scale(((float)canvas.Width) / (float)skiaView.Width, ((float)canvas.Height) / (float)skiaView.Height);
                    iskiaView.SendDraw(skcanvas);
                }
            }
            finally {
                bitmap.UnlockPixels();
            }

            canvas.DrawBitmap(bitmap, 0, 0, null);
        }
        static Bitmap GetCroppedBitmap (Bitmap bmp, int radius)
        {
            Bitmap sbmp;
            if (bmp.Width != radius || bmp.Height != radius)
                sbmp = Bitmap.CreateScaledBitmap (bmp, radius, radius, false);
            else
                sbmp = bmp;
            var output = Bitmap.CreateBitmap (sbmp.Width,
                             sbmp.Height, Bitmap.Config.Argb8888);
            var canvas = new Canvas (output);

            var paint = new Paint ();
            var rect = new Rect (0, 0, sbmp.Width, sbmp.Height);

            paint.AntiAlias = true;
            paint.FilterBitmap = true;
            paint.Dither = true;
            canvas.DrawARGB (0, 0, 0, 0);
            paint.Color = Color.ParseColor ("#BAB399");
            canvas.DrawCircle (sbmp.Width / 2 + 0.7f, sbmp.Height / 2 + 0.7f,
                sbmp.Width / 2 + 0.1f, paint);
            paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcIn));
            canvas.DrawBitmap (sbmp, rect, rect, paint);

            return output;
        }
Exemple #6
0
            public override void Draw(ACanvas canvas)
            {
                int width  = Bounds.Width();
                int height = Bounds.Height();

                if (width <= 0 || height <= 0)
                {
                    if (_normalBitmap != null)
                    {
                        _normalBitmap.Dispose();
                        _normalBitmap = null;
                    }
                    return;
                }

                if (_normalBitmap == null || _normalBitmap.Height != height || _normalBitmap.Width != width)
                {
                    if (_normalBitmap != null)
                    {
                        _normalBitmap.Dispose();
                        _normalBitmap = null;
                    }

                    _normalBitmap = CreateBitmap(false, width, height);
                }
                Bitmap bitmap = _normalBitmap;

                using (var paint = new Paint())
                    canvas.DrawBitmap(bitmap, 0, 0, paint);
            }
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            base.OnDraw(canvas);

            if (_bitmap == null || _bitmap.Width != canvas.Width || _bitmap.Height != canvas.Height)
            {
                if (_bitmap != null)
                {
                    _bitmap.Dispose();
                }

                _bitmap = Bitmap.CreateBitmap(canvas.Width, canvas.Height, Bitmap.Config.Argb8888);
            }

            try
            {
                using (var surface = SKSurface.Create(canvas.Width, canvas.Height, SKColorType.Rgba8888 /*N_32*/, SKAlphaType.Premul, _bitmap.LockPixels(), canvas.Width * 4)) {
                    var skcanvas = surface.Canvas;
                    skcanvas.Scale(((float)canvas.Width) / (float)_tategumiView.Width, ((float)canvas.Height) / (float)_tategumiView.Height);
                    _tateView.SendDraw(skcanvas);
                }
            }
            finally {
                _bitmap.UnlockPixels();
            }

            canvas.DrawBitmap(_bitmap, 0, 0, null);
        }
		protected override void OnDraw (Canvas canvas)
		{
			
			drawCanvas = canvas;
			canvas.DrawBitmap(canvasBitmap, 0, 0, canvasPaint);
			canvas.DrawPath(drawPath, drawPaint);
		}
        public static void Draw(Canvas canvas, IViewport viewport, IStyle style, IFeature feature)
        {
            try
            {
                if (!feature.RenderedGeometry.ContainsKey(style)) feature.RenderedGeometry[style] = ToAndroidBitmap(feature.Geometry);
                var bitmap = (AndroidGraphics.Bitmap)feature.RenderedGeometry[style];
                
                var dest = WorldToScreen(viewport, feature.Geometry.GetBoundingBox());
                dest = new BoundingBox(
                    dest.MinX,
                    dest.MinY,
                    dest.MaxX,
                    dest.MaxY);

                var destination = RoundToPixel(dest);
                using (var paint = new Paint())
                {
                    canvas.DrawBitmap(bitmap, new Rect(0, 0, bitmap.Width, bitmap.Height), destination, paint);
                }

                DrawOutline(canvas, style, destination);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

        }
		public static Bitmap ToBlurred(Bitmap source, Context context, float radius)
		{
			if ((int)Android.OS.Build.VERSION.SdkInt >= 17)
			{
				Bitmap bitmap = Bitmap.CreateBitmap(source.Width, source.Height, Bitmap.Config.Argb8888);

				using (Canvas canvas = new Canvas(bitmap))
				{
					canvas.DrawBitmap(source, 0, 0, null);
					using (Android.Renderscripts.RenderScript rs = Android.Renderscripts.RenderScript.Create(context))
					{
						using (Android.Renderscripts.Allocation overlayAlloc = Android.Renderscripts.Allocation.CreateFromBitmap(rs, bitmap))
						{
							using (Android.Renderscripts.ScriptIntrinsicBlur blur = Android.Renderscripts.ScriptIntrinsicBlur.Create(rs, overlayAlloc.Element))
							{
								blur.SetInput(overlayAlloc);
								blur.SetRadius(radius);	
								blur.ForEach(overlayAlloc);
								overlayAlloc.CopyTo(bitmap);

								rs.Destroy();
								return bitmap;
							}
						}
					}
				}
			}

			return ToLegacyBlurred(source, context, (int)radius);
		}
Exemple #11
0
            public override void Draw(ACanvas canvas)
            {
                int width  = Bounds.Width();
                int height = Bounds.Height();

                if (width <= 0 || height <= 0)
                {
                    if (_normalBitmap != null)
                    {
                        _normalBitmap.Dispose();
                        _normalBitmap = null;
                    }
                    return;
                }

                if (_normalBitmap == null || _normalBitmap.Height != height || _normalBitmap.Width != width)
                {
                    // If the user changes the orientation of the screen, make sure to destroy reference before
                    // reassigning a new bitmap reference.
                    if (_normalBitmap != null)
                    {
                        _normalBitmap.Dispose();
                        _normalBitmap = null;
                    }

                    _normalBitmap = CreateBitmap(false, width, height);
                }
                Bitmap bitmap = _normalBitmap;

                using (var paint = new Paint())
                    canvas.DrawBitmap(bitmap, 0, 0, paint);
            }
Exemple #12
0
        public override void Draw(Canvas canvas)
        {
            LoadResources ();

            var blackPaint = new Paint () { Color = black.Value };
            var whitePaint = new Paint () { Color = white.Value };

            XamGame.RenderBoard ((RectangleF rect, Square.ColourNames color) =>
            {
                var paint = color == Square.ColourNames.White ? whitePaint : blackPaint;
                canvas.DrawRect (rect.X, rect.Y, rect.Right, rect.Bottom, paint);

            }, (RectangleF rect, object image) =>
            {
                if (image != null)
                    canvas.DrawBitmap ((Bitmap) image, rect.Left, rect.Top, null);
            });

            // New Game button
            whitePaint.Color = white.Value;
            whitePaint.SetStyle (Paint.Style.Fill);
            whitePaint.TextSize = 30;
            whitePaint.AntiAlias = true;
            Rect bounds = new Rect ();
            whitePaint.GetTextBounds ("New Game", 0, 8, bounds);
            canvas.DrawText ("New Game", (this.Width - bounds.Width ()) / 2, this.Bottom - (XamGame.BoardUpperLeftCorner.Y - bounds.Height ()) / 2, whitePaint);

            whitePaint.Dispose ();
            blackPaint.Dispose ();

            base.Draw (canvas);
        }
Exemple #13
0
        public override void Draw(ACanvas canvas)
        {
            int width  = Bounds.Width();
            int height = Bounds.Height();

            if (width <= 0 || height <= 0)
            {
                DisposeBitmap();

                return;
            }

            try
            {
                if (_normalBitmap == null || _normalBitmap.Height != height || _normalBitmap.Width != width)
                {
                    // If the user changes the orientation of the screen, make sure to destroy reference before
                    // reassigning a new bitmap reference.
                    DisposeBitmap();

                    _normalBitmap = CreateBitmap(false, width, height);
                }
            }
            catch (ObjectDisposedException)
            {
                // This bitmap will sometimes be disposed as ListView/CollectionView scrolling or refreshing happens,
                // so we re-create the bitmap again.
                _normalBitmap = CreateBitmap(false, width, height);
            }

            using (var paint = new Paint())
            {
                canvas.DrawBitmap(_normalBitmap, 0, 0, paint);
            }
        }
Exemple #14
0
        void DrawBackground()
        {
            if (background != null) {
                background.Dispose ();
            }
            background = Bitmap.CreateBitmap(screen_size.Width, screen_size.Height, Bitmap.Config.Argb8888);
            Canvas c = new Canvas (background);
            //Paint black = new Paint();
            //black.SetARGB(255, 0, 0, 0);
            //black.SetStyle (Paint.Style.Stroke);
            //Bitmap plaatje = blokken[2].DrawBlok (MainActivity.context);

            //DrawBitmap werkt niet voor scaling bitmaps in xamarin
            //c.DrawBitmap (plaatje, new Rect (0, 0, plaatje.Width, plaatje.Height), new RectF (blokken[2].X, blokken[2].Y, blokken[2].Width, blokken[2].Height), null);
            //c.DrawBitmap(plaatje,96,0,null);

            foreach (Blok b in blokken)
            {
                Bitmap plaatje = b.DrawBlok (MainActivity.context);
                c.DrawBitmap (plaatje, b.X, b.Y, null);
                plaatje.Dispose ();
            }
            c.Dispose ();
            //black.Dispose ();
        }
		// If you would like to create a circle of the image set pixels to half the width of the image.
		internal static   Bitmap GetRoundedCornerBitmap(Bitmap bitmap, int pixels)
		{
			Bitmap output = null;

			try
			{
				output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
				Canvas canvas = new Canvas(output);

				Color color = new Color(66, 66, 66);
				Paint paint = new Paint();
				Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
				RectF rectF = new RectF(rect);
				float roundPx = pixels;

				paint.AntiAlias = true;
				canvas.DrawARGB(0, 0, 0, 0);
				paint.Color = color;
				canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);

				paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
				canvas.DrawBitmap(bitmap, rect, rect, paint);
			}
			catch (System.Exception err)
			{
				System.Console.WriteLine ("GetRoundedCornerBitmap Error - " + err.Message);
			}

			return output;
		}
 protected override void OnDraw(Android.Graphics.Canvas canvas)
 {
     if (matrix != null)
     {
         canvas.DrawBitmap(App.bitmap, matrix, null);
     }
     base.OnDraw(canvas);
 }
Exemple #17
0
		protected override void OnDraw(Canvas canvas)
		{
			base.OnDraw(canvas);

			DrawPaint.Color = CurrentLineColor;
			canvas.DrawBitmap(CanvasBitmap, 0, 0, CanvasPaint);
			canvas.DrawPath(DrawPath, DrawPaint);
		}
Exemple #18
0
		public Java.Lang.Object Evaluate (float fraction, Java.Lang.Object startValue, Java.Lang.Object endValue)
		{
			var bmp1 = startValue as Bitmap;
			var bmp2 = endValue as Bitmap;
			if (cacheBitmap == null)
				cacheBitmap = Bitmap.CreateBitmap (bmp1.Width, bmp1.Height, Bitmap.Config.Argb8888);
			if (blendPaint == null) {
				blendPaint = new Paint ();
				blendPaint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcOver));
			}

			using (var canvas = new Canvas (cacheBitmap)) {
				canvas.DrawBitmap (bmp1, 0, 0, null);
				blendPaint.Alpha = (int)((1 - fraction) * 255);
				canvas.DrawBitmap (bmp2, 0, 0, blendPaint);
			}
			return cacheBitmap;
		}
Exemple #19
0
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            if (_reinitializeImages)
            {
                InitializeImages();
                _reinitializeImages = false;
            }

            UpdateSizes();

            // Clear the canvas
            canvas.DrawARGB(255, 255, 255, 255);

            if (_centerBitmap != null && _centerBitmap.Bitmap != null)
            {
                var dest = CalculateCentrationRect(_centerBitmap.Bitmap);
                canvas.DrawBitmap(_centerBitmap.Bitmap, dest.Left + _swipeCurrectXOffset, dest.Top, null);
            }
            else if (_centerBitmap != null)
            {
                DrawLoadingText(canvas, 0);
            }

            if (_leftBitmap != null && _leftBitmap.Bitmap != null)
            {
                var dest = CalculateCentrationRect(_leftBitmap.Bitmap);
                canvas.DrawBitmap(_leftBitmap.Bitmap, dest.Left + _swipeCurrectXOffset - this.Width, dest.Top, null);
            }
            else if (_leftBitmap != null)
            {
                DrawLoadingText(canvas, -Width);
            }

            if (_rightBitmap != null && _rightBitmap.Bitmap != null)
            {
                var dest = CalculateCentrationRect(_rightBitmap.Bitmap);
                canvas.DrawBitmap(_rightBitmap.Bitmap, dest.Left + _swipeCurrectXOffset + this.Width, dest.Top, null);
            }
            else if (_rightBitmap != null)
            {
                DrawLoadingText(canvas, Width);
            }
        }
 public static Bitmap Overlay(IEnumerable<Bitmap> bmps, Bitmap.Config config = null)
 {
     int width = bmps.Max<Bitmap>(x => x.Width);
     int height = bmps.Max<Bitmap>(x => x.Height);
     Bitmap bmOverlay = Bitmap.CreateBitmap(width, height, config == null ? Bitmap.Config.Argb8888 : config);
     Canvas canvas = new Canvas(bmOverlay);
     foreach (var bmp in bmps)
         canvas.DrawBitmap(bmp, 0, 0, null);
     canvas.Dispose();
     return bmOverlay;
 }
Exemple #21
0
        public override void OnDrawItemIcon(Android.Graphics.Canvas canvas, PoiViewItem item, float startX, float endY)
        {
            int circleSize = 42;

            canvas.DrawCircle(startX, ToPixels(circleSize), ToPixels(circleSize), paintBlack);
            canvas.DrawCircle(startX, ToPixels(circleSize), ToPixels(circleSize - 3), item.Selected ? paintWhite : paintGray);

            var bmp = poiCategoryBitmapProvider.GetCategoryIcon(item.Poi.Category);

            canvas.DrawBitmap(bmp, startX - ToPixels(33), ToPixels(circleSize - 33), null /*ColorFilterPoiItem.GetPaintFilter(item)*/);
        }
 public static Bitmap ConvertConfig(Bitmap bitmap, Bitmap.Config config)
 {
     if (bitmap.GetConfig().Equals(config))
         return Bitmap.CreateBitmap(bitmap);
     Bitmap convertedBitmap = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, config);
     Canvas canvas = new Canvas(convertedBitmap);
     Android.Graphics.Paint paint = new Android.Graphics.Paint();
     paint.Color = Android.Graphics.Color.Black;
     canvas.DrawBitmap(bitmap, 0, 0, paint);
     return convertedBitmap;
 }
Exemple #23
0
        public static void Draw(Canvas canvas, IViewport viewport, IStyle style, IFeature feature)
        {
            var point = feature.Geometry as Point;
            var dest = viewport.WorldToScreen(point);
            var symbolSize = (float)SymbolStyle.DefaultHeight;
            var symbolType = SymbolType.Ellipse;

            var symbolStyle = style as SymbolStyle;
            if (symbolStyle != null)
            {
                if (symbolStyle.BitmapId >= 0)
                {
                    // Bitmap
                    if (!feature.RenderedGeometry.ContainsKey(style))
                    {
                        var imageStream = BitmapRegistry.Instance.Get(symbolStyle.BitmapId);
                        imageStream.Position = 0;
                        var androidBitmap = BitmapFactory.DecodeStream(imageStream);
                        feature.RenderedGeometry[style] = androidBitmap;
                    }

                    var bitmap = (Bitmap)feature.RenderedGeometry[style];
                    var halfWidth = bitmap.Width / 2;
                    var halfHeight = bitmap.Height / 2;
                    var dstRectForRender = new RectF((float)dest.X - halfWidth, (float)dest.Y - halfHeight, (float)dest.X + halfWidth, (float)dest.Y + halfHeight);
                    canvas.DrawBitmap(bitmap, null, dstRectForRender, null);
                    return;
                }
                symbolType = symbolStyle.SymbolType;
                if (symbolStyle.SymbolScale > 0) symbolSize = (float)symbolStyle.SymbolScale * symbolSize;
            }

            // Drawing
            var paints = style.ToAndroid();
            if (symbolType == SymbolType.Ellipse)
            {
                foreach (var paint in paints)
                {
                    canvas.DrawCircle((int)dest.X, (int)dest.Y, symbolSize, paint);
                    paint.Dispose();
                }
            }
            else
            {
                foreach (var paint in paints)
                {
                    canvas.DrawRect(-(float)SymbolStyle.DefaultWidth, (float)SymbolStyle.DefaultHeight, (float)SymbolStyle.DefaultWidth, -(float)SymbolStyle.DefaultHeight, paint);
                    paint.Dispose();
                }
            }
        }
Exemple #24
0
 public static Bitmap GetRoundedCornerBitmap(this Bitmap bitmap, int roundPixelSize)
 {
     Bitmap output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
     var canvas = new Canvas(output);
     var paint = new Paint();
     var rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
     var rectF = new RectF(rect);
     var roundPx = roundPixelSize;
     paint.AntiAlias = true;
     canvas.DrawRoundRect(rectF,roundPx,roundPx, paint);
     paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
     canvas.DrawBitmap(bitmap, rect, rect, paint);
     return output;
 }
        protected override 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);
            Paint paint = new Paint();
            paint.AntiAlias = true;
            paint.SetColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SrcAtop));
            canvas.DrawBitmap(source, 0, 0, paint);
            source.Recycle();

            return bitmap;
        }
        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;
        } 
		public static Bitmap ToColorSpace(Bitmap source, ColorMatrix colorMatrix)
		{
			int width = source.Width;
			int height = source.Height;

			Bitmap bitmap = Bitmap.CreateBitmap(width, height, source.GetConfig());

			using (Canvas canvas = new Canvas(bitmap))
			using (Paint paint = new Paint())
			{
				paint.SetColorFilter(new ColorMatrixColorFilter(colorMatrix));
				canvas.DrawBitmap(source, 0, 0, paint);

				return bitmap;	
			}
		}
 public static Bitmap GetRoundedCornerBitmap(this Bitmap bitmap, int? roundPixelSize = null)
 {
     var chooseSize = bitmap.Width > bitmap.Height ? bitmap.Height : bitmap.Width;
     roundPixelSize = roundPixelSize ?? (int)Application.Context.Resources.GetDimension(Resource.Dimension.RoundedCorners);
     var output = Bitmap.CreateBitmap(chooseSize, chooseSize, Bitmap.Config.Argb8888);
     var canvas = new Canvas(output);
     var paint = new Paint();
     var rect = new Rect(0, 0, chooseSize, chooseSize);
     var rectF = new RectF(rect);
     var roundPx = roundPixelSize.Value;
     paint.AntiAlias = true;
     canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);
     paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
     canvas.DrawBitmap(bitmap, rect, rect, paint);
     return output;
 }
                public static void CreateAlphaMask(Android.Content.Context context, string fileName)
                {
                    // load the stream from assets
                    System.IO.Stream assetStream = context.Assets.Open(fileName);

                    // grab the RGBA mask
                    Bitmap rgbaMask = BitmapFactory.DecodeStream(assetStream);

                    // convert it to an alpha mask
                    AlphaMask = Bitmap.CreateBitmap(rgbaMask.Width, rgbaMask.Height, Bitmap.Config.Alpha8);

                    // put the 8bit mask into a canvas
                    Android.Graphics.Canvas maskCanvas = new Android.Graphics.Canvas(AlphaMask);

                    // render the rgb mask into the canvas, which writes the result into the AlphaMask bitmap
                    maskCanvas.DrawBitmap(rgbaMask, 0.0f, 0.0f, null);
                }
        protected override 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;
        }
		public static Bitmap ToRotatedBitmap(this Bitmap sourceBitmap, int rotationDegrees)
		{
			if (rotationDegrees == 0)
				return sourceBitmap;

			int width = sourceBitmap.Width;
			int height = sourceBitmap.Height;

			if (rotationDegrees == 90 || rotationDegrees == 270)
			{
				width = sourceBitmap.Height;
				height = sourceBitmap.Width;
			}

			Bitmap bitmap = Bitmap.CreateBitmap(width, height, sourceBitmap.GetConfig());
			using (Canvas canvas = new Canvas(bitmap))
			using (Paint paint = new Paint())
			using (BitmapShader shader = new BitmapShader(sourceBitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
			using (Matrix matrix = new Matrix())
			{
				// paint.AntiAlias = true;
				// paint.Dither = true;
				// paint.FilterBitmap = true;

				canvas.Save(Android.Graphics.SaveFlags.Matrix);

				if (rotationDegrees == 90)
					canvas.Rotate(rotationDegrees, width / 2, width / 2);
				else if (rotationDegrees == 270)
					canvas.Rotate(rotationDegrees, height / 2, height / 2);
				else
					canvas.Rotate(rotationDegrees, width / 2, height / 2);

				canvas.DrawBitmap(sourceBitmap, matrix, paint);
				canvas.Restore();
			}

			if (sourceBitmap != null && sourceBitmap.Handle != IntPtr.Zero && !sourceBitmap.IsRecycled)
			{
				sourceBitmap.Recycle();
				sourceBitmap.Dispose();
			}

			return bitmap;
		}
Exemple #32
0
		public override void Draw(Canvas canvas)
		{
			int width = Bounds.Width();
			int height = Bounds.Height();

			if (width <= 0 || height <= 0)
				return;

			if (_normalBitmap == null || _normalBitmap.Height != height || _normalBitmap.Width != width)
			{
				Reset();

				_normalBitmap = CreateBitmap(false, width, height);
				_pressedBitmap = CreateBitmap(true, width, height);
			}

			Bitmap bitmap = GetState().Contains(global::Android.Resource.Attribute.StatePressed) ? _pressedBitmap : _normalBitmap;
			canvas.DrawBitmap(bitmap, 0, 0, new Paint());
		}
        protected override void OnDraw (Canvas canvas)
        {
            var drawable = Drawable;

            if (drawable == null) return;

            if (Width == 0 || Height == 0) return;

            var b = ((BitmapDrawable)drawable).Bitmap;
            if (b == null) return;

            var bitmap = b.Copy (Bitmap.Config.Argb8888, true);

            var w = Width;
            var h = Height;

            var roundBitmap = GetCroppedBitmap (bitmap, w);
            canvas.DrawBitmap (roundBitmap, 0, 0, null);
        }
        protected override Android.Graphics.Bitmap Transform(Android.Graphics.Bitmap source)
        {
            Bitmap outBitmap = Bitmap.CreateBitmap(source.Width, source.Height, Bitmap.Config.Argb8888);
            Canvas canvas = new Canvas(outBitmap);
            canvas.DrawBitmap(source, 0, 0, null);

            RenderScript rs = RenderScript.Create(mContext);
            Allocation overlayAlloc = Allocation.CreateFromBitmap(rs, outBitmap);
            ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.Create(rs, overlayAlloc.Element);
            blur.SetInput(overlayAlloc);
            blur.SetRadius(mRadius);
            blur.ForEach(overlayAlloc);
            overlayAlloc.CopyTo(outBitmap);

            source.Recycle();
            rs.Destroy();

            return outBitmap;
        }
        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 override void Draw(ACanvas canvas)
        {
            int width  = Bounds.Width();
            int height = Bounds.Height();

            if (width <= 0 || height <= 0)
            {
                return;
            }

            if (_normalBitmap == null || _normalBitmap.Handle == IntPtr.Zero ||
                _normalBitmap.Height != height || _normalBitmap.Width != width)
            {
                Reset();
            }

            _normalBitmap = _normalBitmap ?? CreateBitmap(width, height);

            canvas.DrawBitmap(_normalBitmap, 0, 0, new Paint());
        }
                protected override void OnDraw(Android.Graphics.Canvas canvas)
                {
                    // if our render buffers are not valid, generate them
                    if (CurrWidth != this.LayoutParameters.Width || CurrHeight != this.LayoutParameters.Height)
                    {
                        CreateTextBitmaps(this.LayoutParameters.Width, this.LayoutParameters.Height);
                        CreateResultBitmaps(this.LayoutParameters.Width, this.LayoutParameters.Height);

                        CurrWidth  = this.LayoutParameters.Width;
                        CurrHeight = this.LayoutParameters.Height;
                    }


                    // keep the spot light centered on the image
                    float xPos = (LayoutParameters.Width / 2) - ((AlphaMask.Width / 2) * MaskScale);
                    float yPos = (LayoutParameters.Height / 2) - ((AlphaMask.Height / 2) * MaskScale);

                    // update the text's transform for the mask scale.
                    // The text's transform should be the inverse of the Canvas' values
                    TextTransform.SetScale(1.0f / MaskScale, 1.0f / MaskScale);
                    TextTransform.PreTranslate(-xPos, -yPos);

                    TextPaint.Shader.SetLocalMatrix(TextTransform);

                    // clear the bitmap before re-rendering. (NOT EFFICIENT _AT_ _ALL_)
                    ResultBmp.SetPixels(new int[ResultBmp.RowBytes * ResultBmp.Height], 0, ResultBmp.RowBytes, 0, 0, ResultBmp.Width, ResultBmp.Height);

                    // save / restore the canvas settings so we don't accumulate the scale
                    ResultCanvas.Save();
                    ResultCanvas.Translate(xPos, yPos);
                    ResultCanvas.Scale(MaskScale, MaskScale);

                    // render the alpha mask'd text to our result bmp
                    ResultCanvas.DrawBitmap(AlphaMask, 0, 0, TextPaint);

                    // restore the canvas values for next time.
                    ResultCanvas.Restore();

                    // and to the actual android buffer, render our result
                    canvas.DrawBitmap(ResultBmp, 0, 0, null);
                }
Exemple #38
0
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            canvas.DrawCircle(mainCenter, mainCenter + 2, radius + radiusBorder, shadowPaint);
            canvas.DrawCircle(mainCenter, mainCenter, radius + radiusBorder, darkerBackPaint);
            canvas.DrawCircle(mainCenter, mainCenter, radius, backPaint);
            canvas.DrawBitmap(icon, mainCenter - icon.Width / 2, mainCenter - icon.Height / 2, imgPaint);

            if (Count != 0)
            {
                int bubbleCenter = center - removeRadius - bubbleOffset;
                greenPaint.Alpha  = redPaint.Alpha = currentBubbleTransparency;
                removePaint.Alpha = 255 - currentBubbleTransparency;
                canvas.DrawCircle(bubbleCenter, bubbleCenter, removeRadius, removePaint);
                canvas.DrawCircle(bubbleCenter, bubbleCenter, innerRadius, Count < 0 ? redPaint : greenPaint);

                var c          = Math.Abs(Count).ToString();
                var textBounds = new Rect();
                removePaint.GetTextBounds(c, 0, c.Length, textBounds);

                canvas.DrawText(c, bubbleCenter, bubbleCenter + textBounds.Height() / 2, removePaint);
            }
            DrawingCacheEnabled = true;
        }
Exemple #39
0
		public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, int targetWidth, int targetHeight)
		{
			
			Bitmap targetBitmap = Bitmap.CreateBitmap(targetWidth,
				targetHeight, Bitmap.Config.Argb8888);

			Canvas canvas = new Canvas(targetBitmap);
			Android.Graphics.Path path = new Android.Graphics.Path();
			path.AddCircle(((float)targetWidth - 1) / 2,
				((float)targetHeight - 1) / 2,
				(Math.Min(((float)targetWidth),
					((float)targetHeight)) / 2),
				Android.Graphics.Path.Direction.Ccw);


			canvas.ClipPath(path);
			Bitmap sourceBitmap = scaleBitmapImage;
			canvas.DrawBitmap(sourceBitmap,
				new Rect(0, 0, sourceBitmap.Width,
					sourceBitmap.Height),
				new Rect(0, 0, targetWidth, targetHeight), null);
			return targetBitmap;
		}
        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);
        }
		protected override void OnDraw (Canvas canvas)
		{
			
			Drawable drawable =  Drawable;

			if (drawable == null) {
				return;
			}

			if (Width == 0 || Height == 0) {
				return;
			}
			Bitmap b = ((BitmapDrawable) drawable).Bitmap;
			Bitmap bitmap = b.Copy(Bitmap.Config.Argb8888, true);

			int w = width, h = height;

			Bitmap roundBitmap =  getRoundedCroppedBitmap(bitmap, w);



			canvas.DrawBitmap(roundBitmap, 0, 0, null);
		}
        protected override void OnDraw(Canvas c)
        {
            Init(c);

            _p.SetStyle (Paint.Style.Fill);
            _p.Color = Color.White;
            c.DrawPaint(_p);

            float scale = (float) _cat.Width / (float) _cat.Height;
            int new_height = c.Height * 3 / 4;
            int new_width = (int) (new_height * scale);
            c.DrawBitmap(
                _cat,
                new Rect(0, 0, _cat.Width, _cat.Height),
                new Rect(0, c.Width / 4, new_width, new_height + c.Width / 4),
                //new Rect(0, (int) (c.Height-new_height), (int) new_width, (int) c.Height),
                _p
            );

            foreach (var purr in _purrs) {
                purr.Render(c, _p);
            }
        }
Exemple #43
0
        protected override void OnDraw(Canvas canvas)
        {
            coreX       = Width / 2;
            coreY       = Height / 2;
            roundRadius = (int)(Width / 2 * radiusDistance); //计算中心圆圈半径

            RectF rect = new RectF(0, 0, Width, Height);

            if (roundMenus != null && roundMenus.Count > 0)
            {
                float sweepAngle = 360 / roundMenus.Count; //每个弧形的角度
                deviationDegree = sweepAngle / 2;          //其实的偏移角度,如果4个扇形的时候是X形状,而非+,设为0试试就知道什么意思了
                for (int i = 0; i < roundMenus.Count; i++)
                {
                    RoundMenu roundMenu = roundMenus[i];
                    //填充
                    Paint paint = new Paint();
                    paint.AntiAlias = true;
                    if (onClickState == i)
                    {
                        //选中
                        paint.Color = new Color(roundMenu.selectSolidColor);
                    }
                    else
                    {
                        //未选中
                        paint.Color = new Color(roundMenu.solidColor);
                    }
                    canvas.DrawArc(rect, deviationDegree + (i * sweepAngle), sweepAngle, true, paint);

                    //画描边
                    paint             = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = roundMenu.strokeSize;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = new Color(roundMenu.strokeColor);
                    canvas.DrawArc(rect, deviationDegree + (i * sweepAngle), sweepAngle, roundMenu.useCenter, paint);

                    //画图案
                    Matrix matrix = new Matrix();
                    matrix.PostTranslate((float)((coreX + Width / 2 * roundMenu.iconDistance) - (roundMenu.icon.Width / 2)), coreY - (roundMenu.icon.Height / 2));
                    matrix.PostRotate(((i + 1) * sweepAngle), coreX, coreY);
                    canvas.DrawBitmap(roundMenu.icon, matrix, null);
                }
            }

            //画中心圆圈
            if (isCoreMenu)
            {
                //填充
                RectF rect1 = new RectF(coreX - roundRadius, coreY - roundRadius, coreX + roundRadius, coreY + roundRadius);
                Paint paint = new Paint();
                paint.AntiAlias   = true;
                paint.StrokeWidth = coreMenuStrokeSize;
                if (onClickState == -1)
                {
                    paint.Color = new Color(coreMenuSelectColor);
                }
                else
                {
                    paint.Color = new Color(coreMenuColor);
                }
                canvas.DrawArc(rect1, 0, 360, true, paint);

                //画描边
                paint             = new Paint();
                paint.AntiAlias   = true;
                paint.StrokeWidth = coreMenuStrokeSize;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = new Color(coreMenuStrokeColor);
                canvas.DrawArc(rect1, 0, 360, true, paint);
                if (coreBitmap != null)
                {
                    //画中心圆圈的"OK"图标
                    canvas.DrawBitmap(coreBitmap, coreX - coreBitmap.Width / 2, coreY - coreBitmap.Height / 2, null); //在 0,0坐标开始画入src
                }
            }
        }
Exemple #44
-1
		public static Bitmap GetImage(int width, int height, string intensiteit)
		{
			intensity = intensiteit;
			sizeBlocks = width / 7;
			int amountImages = 56;
			List<Bitmap> bitmaps = DrawImages.CreateBitmapBlocks (amountImages,false);
			Paint p = new Paint ();
			p.StrokeWidth = 0.5f;
			p.SetStyle (Paint.Style.Fill);
			p.Color = Color.White;
			Bitmap b = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888);
			Canvas c = new Canvas (b);
			//Make background White
			c.DrawRect (new Rect (0, 0, width, height), p);
			//Draw Blocks
			for(int i=0;i<amountImages;i++)
			{
				c.DrawBitmap (bitmaps[i], (i % 7) * (width / 7), (i % 8) * (height / 8), p);
			}
			p.Dispose ();
			c.Dispose ();
			return b;
		}