Exemplo n.º 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;
 }
Exemplo n.º 2
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 ();
        }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 private MemoryStream RenderToBitmapStreamPrivate(IViewport viewport, IEnumerable<ILayer> layers)
 {
     Bitmap target = Bitmap.CreateBitmap((int)viewport.Width, (int)viewport.Height, Bitmap.Config.Argb8888);
     var canvas = new Canvas(target);
     Render(canvas, viewport, layers, ShowDebugInfoInMap);
     var stream = new MemoryStream();
     target.Compress(Bitmap.CompressFormat.Png, 100, stream);
     target.Dispose();
     canvas.Dispose();
     return stream;
 }
        public Android.Graphics.Bitmap BitmapFromView(Android.Views.View nativeView)
        {
            Android.Graphics.Bitmap bitmap = Android.Graphics.Bitmap.CreateBitmap(nativeView.Width, nativeView.Height, Android.Graphics.Bitmap.Config.Argb8888);

            Android.Graphics.Canvas canvas = new Android.Graphics.Canvas(bitmap);

            nativeView.Draw(canvas);

            canvas.Dispose();

            return(bitmap);
        }
Exemplo n.º 6
0
        //--------------------------------------------------------------
        // PROTECTED METHODS
        //--------------------------------------------------------------
        protected bool InitializeUI()
        {
            _buttonLayout.SetMinimumHeight(Math.Max(_positiveButton.Height, _negativeButton.Height));

            // Initialize background
            if(_root.Width <= 0 || _root.Height <= 0)
                return false;

            if(_backgroundImage != null)
            {
                _backgroundImage.Recycle();
                _backgroundImage.Dispose();
            }

            _backgroundImage = Bitmap.CreateBitmap(_root.Width, _root.Height, Bitmap.Config.Argb8888);
            Canvas canvas = new Canvas(_backgroundImage);

            Rect local = new Rect();
            _root.GetLocalVisibleRect(local);
            RectF bounds = new RectF(local);
            bounds.Top += Builder.StrokeBorderWidth/2;
            bounds.Left += Builder.StrokeBorderWidth/2;
            bounds.Right -= Builder.StrokeBorderWidth/2;
            bounds.Bottom -= Builder.StrokeBorderWidth/2;

            // Background fill paint
            Paint fillBackPaint = new Paint();
            fillBackPaint.Color = Builder.FillColor;
            fillBackPaint.AntiAlias = true;

            // Background stroke paint
            Paint strokeBackPaint = new Paint();
            strokeBackPaint.Color = Builder.StrokeColor;
            strokeBackPaint.SetStyle(Paint.Style.Stroke);
            strokeBackPaint.StrokeWidth = Builder.StrokeBorderWidth;
            strokeBackPaint.AntiAlias = true;

            canvas.DrawRoundRect(bounds, Builder.RadiusOut, Builder.RadiusOut, strokeBackPaint);
            canvas.DrawRoundRect(bounds, Builder.RadiusIn, Builder.RadiusIn, fillBackPaint);

            _root.SetBackgroundDrawable(new BitmapDrawable(_backgroundImage));

            canvas.Dispose();
            strokeBackPaint.Dispose();
            fillBackPaint.Dispose();

            return true;
        }
        private void loadProfilePicture(Guid contactId)
        {
            if (contactId != null) {
                ContactDB cont = new ContactDB ();
                if (contacts.ContainsKey (contactId))
                    cont = contacts [contactId];

                byte[] imgdata = cont.ContactUser.Picture;
                Bitmap original = BitmapFactory.DecodeByteArray (imgdata, 0, imgdata.Length);
                Bitmap mask = Bitmap.CreateScaledBitmap (BitmapFactory.DecodeResource (Resources, Resource.Drawable.emptybackground), original.Width, original.Height, true);
                Bitmap result = Bitmap.CreateBitmap (mask.Width, mask.Height, Bitmap.Config.Argb8888);
                Canvas canv = new Canvas (result);
                Paint paint = new Paint (PaintFlags.AntiAlias);

                paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.DstIn));
                canv.DrawBitmap (original, 0, 0, null);
                canv.DrawBitmap (mask, 0, 0, paint);
                paint.SetXfermode (null);

                RunOnUiThread (delegate {
                    ImageView pic = (ImageView)converse.FindViewWithTag (new Java.Lang.String ("profilepic_" + contactId.ToString ()));
                    pic.SetImageBitmap (result);
                    original.Dispose ();
                    mask.Dispose ();
                    paint.Dispose ();
                    canv.Dispose ();
                    result.Dispose ();
                });
            }
        }
Exemplo n.º 8
0
        //--------------------------------------------------------------
        // STATIC METHODS
        //--------------------------------------------------------------
        public static Bitmap CreateImage(int blockSize, TetrisColor color)
        {
            if(color == TetrisColor.ColorMax)
                return null;

            // Create the image with its canvas to draw in it
            Bitmap image = Bitmap.CreateBitmap(blockSize, blockSize, Bitmap.Config.Argb8888);
            Canvas imageCanvas = new Canvas(image);

            // Calculate the width of the borders with a percentage of the size of the block
            float borderWidth = BorderWidth * blockSize;
            float borderWidth3D = BorderWidth3D * blockSize;

            // Calculate all the colors for the block based on its tetris color
            Color baseColor = adjustColor(Utils.getAndroidColor(color), SvBaseColor);
            Color topColor = adjustColor(baseColor, SvTopColor);
            Color leftColor = adjustColor(baseColor, SvLeftColor);
            Color rightColor = adjustColor(baseColor, SvRightColor);
            Color bottomColor = adjustColor(baseColor, SvBottomColor);
            Color borderColor = adjustColor(baseColor, SvBorderColor);

            // Draw the border
            Paint borderPaint = new Paint {AntiAlias = true, Color = borderColor};
            for(int i = 0 ; i < BorderWidth ; i++)
            {
                imageCanvas.DrawRect(i, blockSize - i, blockSize - i, i, borderPaint);
            }
            borderPaint.Dispose();

            // Define the corners of the big rectangle without the border
            PointF outerRectTopLeft = new PointF(
                borderWidth,
                borderWidth);
            PointF outerRectTopRight = new PointF(
                blockSize - borderWidth,
                borderWidth);
            PointF outerRectBottomRight = new PointF(
                blockSize - borderWidth,
                blockSize - borderWidth);
            PointF outerRectBottomLeft = new PointF(
                borderWidth,
                blockSize - borderWidth);

            // Define the corners of the small rectangle in the middle
            PointF innerRectTopLeft = new PointF(
                borderWidth + borderWidth3D,
                borderWidth + borderWidth3D);
            PointF innerRectTopRight = new PointF(
                blockSize -borderWidth - borderWidth3D,
                borderWidth + borderWidth3D);
            PointF innerRectBottomRight = new PointF(
                blockSize -borderWidth - borderWidth3D,
                blockSize -borderWidth - borderWidth3D);
            PointF innerRectBottomLeft = new PointF(
                borderWidth + borderWidth3D,
                blockSize -borderWidth - borderWidth3D);

            // Draw inner square
            PointF[] innerSquare = new[]
            {
                innerRectTopLeft,
                innerRectTopRight,
                innerRectBottomRight,
                innerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, innerSquare, baseColor);

            // Draw top 3D border
            PointF[] top3dBorder = new[]
            {
                outerRectTopLeft,
                outerRectTopRight,
                innerRectTopRight,
                innerRectTopLeft
            };
            drawPolygonInCanvas(imageCanvas, top3dBorder, topColor);

            // Draw bottom 3D border
            PointF[] bottom3dBorder = new[]
            {
                innerRectBottomLeft,
                innerRectBottomRight,
                outerRectBottomRight,
                outerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, bottom3dBorder, bottomColor);

            // Draw left 3D border
            PointF[] left3dBorder = new[]
            {
                outerRectTopLeft,
                innerRectTopLeft,
                innerRectBottomLeft,
                outerRectBottomLeft
            };
            drawPolygonInCanvas(imageCanvas, left3dBorder, leftColor);

            // Draw right 3D border
            PointF[] right3dBorder = new[]
            {
                innerRectTopRight,
                outerRectTopRight,
                outerRectBottomRight,
                innerRectBottomRight
            };
            drawPolygonInCanvas(imageCanvas, right3dBorder, rightColor);

            imageCanvas.Dispose();

            return image;
        }
Exemplo n.º 9
0
        public void DrawMap()
        {
            // Clean up
            ResetMap();
            // Get out drawing 
            var canvas = new Canvas(CurrentImage);

            if (StartPoint != null)
                canvas.DrawCircle(StartPoint.X, StartPoint.Y, 20, PaintBrush);

            if (EndPoint != null)
                canvas.DrawCircle(EndPoint.X, EndPoint.Y, 20, PaintBrush);

            if (UserPosition != null)
            {
                // Just some maths to scale the image (we dont want a big arrow at least not for now lol)
                canvas.DrawBitmap(CurrentUserRepresentation, UserPosition.X - CurrentUserRepresentation.Width/2,
                    UserPosition.Y - CurrentUserRepresentation.Height/2, PaintBrush);
            }

            if (StartPoint != null && EndPoint != null)
            {
                // Map points 
                var startPoint = PathfindingGraph.FindClosestNode((int) StartPoint.X, (int) StartPoint.Y);
                var endPoint = PathfindingGraph.FindClosestNode((int) EndPoint.X, (int) EndPoint.Y);
                UserPath = PathfindingGraph.FindPath(startPoint, endPoint);
            }

            if (UserPath.Count > 0)
            {
                PaintBrush.StrokeWidth = 5;
                PaintBrush.Color = Color.Red;
                // If we have some path, draw it
                foreach (var edge in UserPath)
                {
                    var start = new Vector2(edge.Source);
                    var target = new Vector2(edge.Target);
                    canvas.DrawLine(start.X, start.Y, target.X, target.Y, PaintBrush);
                }
            }
            canvas.Dispose();
            CIVInstance.SetImageBitmap(CurrentImage);
        }
Exemplo n.º 10
0
        private void DrawFirstBitmap()
        {
            if(_grid == null)
                return; // if the gridView haven't been initialized, we stop

            if(_firstBitmapBuffer != null)
                return;

            _firstBitmapBuffer = Bitmap.CreateBitmap(Width, Height, Bitmap.Config.Argb8888);

            Canvas bitmapCanvas = new Canvas(_firstBitmapBuffer);

            // If it is the first draw, calculate the size of the block according to the size of the canvas
            if (_blockSize == 0)
            {
                // Calculate the size of the block
                /*Rect rect = new Rect();
                GetDrawingRect(rect);
                int height = Math.Abs(rect.Bottom - rect.Top);
                int width = Math.Abs(rect.Right - rect.Left);*/
                _strokeWidthBorder = calculateBorderSize(Width, Height);
                _blockSize = CalculateBlockSize(Width, Height, _strokeWidthBorder);

                // Create the blocks images with the right size
                foreach(TetrisColor color in Enum.GetValues(typeof(TetrisColor)))
                {
                    Bitmap image = BlockView.CreateImage(_blockSize, color);
                    if(image != null)
                    {
                        _blockImages.Add(color, image);
                    }
                }
            }

            // Calculate the boundaries of the grid
            float left = _blockSize*Constants.GridSizeXmin + _strokeWidthBorder;
            float top = _blockSize*Constants.GridSizeYmin + _strokeWidthBorder; // the O point is in the left hand corner
            float right = _blockSize*(Constants.GridSizeXmax+1) + _strokeWidthBorder;
            float bottom = _blockSize*(Constants.GridSizeYmax+1) + _strokeWidthBorder;

            // Draw the background
            bitmapCanvas.DrawRect(left, top, right, bottom, BackgroundPaint);

            // Draw the borders
            bitmapCanvas.DrawRect(0, top - _strokeWidthBorder, _strokeWidthBorder, bottom + _strokeWidthBorder, BorderPaint);
            bitmapCanvas.DrawRect(right, top - _strokeWidthBorder, right + _strokeWidthBorder, bottom + _strokeWidthBorder, BorderPaint);
            bitmapCanvas.DrawRect(left - _strokeWidthBorder, 0, right + _strokeWidthBorder, _strokeWidthBorder, BorderPaint);
            bitmapCanvas.DrawRect(left - _strokeWidthBorder, bottom, right + _strokeWidthBorder, bottom +  _strokeWidthBorder, BorderPaint);

            // Draw the vertical quartering
            for(float x = left + _blockSize; x < right ; x += _blockSize)
            {
                bitmapCanvas.DrawRect(x - _strokeWidthBorder / 2, top, x + _strokeWidthBorder - _strokeWidthBorder / 2, bottom, GridPaint);
            }

            // Draw the horizontal quartering
            for(float y = top + _blockSize; y < bottom ; y += _blockSize)
            {
                bitmapCanvas.DrawRect(left, y - _strokeWidthBorder / 2, right, y + _strokeWidthBorder - _strokeWidthBorder / 2, GridPaint);
            }

            bitmapCanvas.Dispose();
        }
Exemplo n.º 11
0
        //--------------------------------------------------------------
        // PRIVATE METHODS
        //--------------------------------------------------------------
        private void DrawBitmap()
        {
            if(_grid == null)
                return; // if the gridView haven't been initialized, we stop

            if(_bitmapBuffer == null)
            {
                _bitmapBuffer = Bitmap.CreateBitmap(Width, Height, Bitmap.Config.Argb8888);
            }

            Canvas bitmapCanvas = new Canvas(_bitmapBuffer);

            if(_firstBitmapBuffer == null)
                DrawFirstBitmap();

            bitmapCanvas.DrawBitmap(_firstBitmapBuffer, 0, 0, null);

            // Draw the blocks
            for (uint i = 0 ; i < _grid._map.GetLength(0) ; i++)
            {
                for (uint j = 0 ; j < _grid._map.GetLength(1) ; j++)
                {
                    _mapView[i,j].Draw(bitmapCanvas, _blockSize, _blockImages, _strokeWidthBorder, _strokeWidthBorder);
                }
            }

            bitmapCanvas.Dispose();

            _redraw = false;
        }
Exemplo n.º 12
0
        private void setBackground()
        {
            LinearLayout player2layout = FindViewById<LinearLayout>(Resource.Id.player2layout);

            if(_player2background != null)
            {
                _player2background.Recycle();
                _player2background.Dispose();
            }
            // Create image
            _player2background = Bitmap.CreateBitmap(player2layout.Width, player2layout.Height, Bitmap.Config.Argb8888);
            Canvas backCanvas = new Canvas(_player2background);

            // Background stroke paint
            float strokeBorderWidth = (FindViewById<ButtonStroked>(Resource.Id.buttonMoveLeft)).Settings.StrokeBorderWidth;
            int padding = (int)strokeBorderWidth/2 + Utils.GetPixelsFromDP(this, 5);
            player2layout.SetPadding(padding, 0, 0, padding);

            Paint strokeBackPaint = new Paint();
            strokeBackPaint.Color = Utils.getAndroidColor(TetrisColor.Red);
            strokeBackPaint.SetStyle(Paint.Style.Stroke);
            strokeBackPaint.StrokeWidth = strokeBorderWidth/2;
            strokeBackPaint.AntiAlias = true;

            // Get rectangle
            Rect local = new Rect();
            player2layout.GetLocalVisibleRect(local);
            RectF bounds = new RectF(local);
            bounds.Left += strokeBorderWidth/2;
            bounds.Bottom -= strokeBorderWidth/2;
            bounds.Top -= strokeBorderWidth;
            bounds.Right += strokeBorderWidth;

            // Actually draw background
            int radiusIn = (FindViewById<ButtonStroked>(Resource.Id.buttonMoveLeft)).Settings.RadiusIn;
            int radiusOut = (FindViewById<ButtonStroked>(Resource.Id.buttonMoveLeft)).Settings.RadiusOut;
            backCanvas.DrawRoundRect(bounds, radiusOut, radiusOut, strokeBackPaint);

            // Use it as background
            player2layout.SetBackgroundDrawable(new BitmapDrawable(_player2background));

            backCanvas.Dispose();
            strokeBackPaint.Dispose();
        }
Exemplo n.º 13
0
        private void InitializeImages()
        {
            if(_pressedImage != null)
            {
                _pressedImage.Recycle();
                _pressedImage.Dispose();
            }
            if(_unpressedImage != null)
            {
                _unpressedImage.Recycle();
                _unpressedImage.Dispose();
            }

            _unpressedImage = Bitmap.CreateBitmap(Width, Settings.IsSquared ? Width : Height, Bitmap.Config.Argb8888);
            _pressedImage = Bitmap.CreateBitmap(Width, Settings.IsSquared ? Width : Height, Bitmap.Config.Argb8888);
            Canvas unpressedCanvas = new Canvas(_unpressedImage);
            Canvas pressedCanvas = new Canvas(_pressedImage);

            Settings.SetTextSize(ComplexUnitType.Px, Settings.TextSize == 0f ? Height * Settings.TextSizeRatio : Settings.TextSize);
            Settings.StrokeBorderWidth = Height * Settings.StrokeBorderWidthRatio;
            Settings.StrokeTextWidth = Height * Settings.StrokeTextWidthRatio;

            // Background fill paint
            Paint fillBackPaint = new Paint();
            fillBackPaint.Color = Settings.FillColor;
            fillBackPaint.AntiAlias = true;

            // Background stroke paint
            Paint strokeBackPaint = new Paint();
            strokeBackPaint.Color = Settings.StrokeColor;
            strokeBackPaint.SetStyle(Paint.Style.Stroke);
            strokeBackPaint.StrokeWidth = Settings.StrokeBorderWidth;
            strokeBackPaint.AntiAlias = true;

            // Text paint
            Paint textPaint = new Paint();
            textPaint.Color = Settings.IsTextStroked ? Settings.FillColor : Settings.StrokeColor;
            textPaint.TextAlign = Paint.Align.Center;
            textPaint.TextSize = Settings.TextSize;
            textPaint.SetTypeface(Settings.Typeface);
            textPaint.AntiAlias = true;

            // Text stroke paint
            Paint strokePaint = new Paint();
            strokePaint.Color = Settings.StrokeColor;
            strokePaint.TextAlign = Paint.Align.Center;
            strokePaint.TextSize = Settings.TextSize;
            strokePaint.SetTypeface(Settings.Typeface);
            strokePaint.SetStyle(Paint.Style.Stroke);
            strokePaint.StrokeWidth = Settings.StrokeTextWidth;
            strokePaint.AntiAlias = true;

            // Background bounds
            Rect local = new Rect();
            this.GetLocalVisibleRect(local);
            RectF bounds = new RectF(local);
            bounds.Top += Settings.StrokeBorderWidth/2;
            bounds.Left += Settings.StrokeBorderWidth/2;
            bounds.Right -= Settings.StrokeBorderWidth/2;
            bounds.Bottom -= Settings.StrokeBorderWidth/2;

            while(bounds.Top > Height)
            {
                bounds.Top -= Height;
            }
            while(bounds.Bottom > Height)
            {
                bounds.Bottom -= Height;
            }
            while(bounds.Left > Width)
            {
                bounds.Left -= Width;
            }
            while(bounds.Right > Width)
            {
                bounds.Right -= Width;
            }

            // Text location
            Rect r = new Rect();
            strokePaint.GetTextBounds(Text, 0, Text.Length, r);
            while(r.Width() + Settings.StrokeTextWidth >= bounds.Width())
            {
                Settings.SetTextSize(ComplexUnitType.Px, Settings.TextSize-1);
                textPaint.TextSize = Settings.TextSize;
                strokePaint.TextSize = Settings.TextSize;
                strokePaint.GetTextBounds(Text, 0, Text.Length, r);
            }

            float x=0, y=0;
            switch (Settings.Gravity)
            {
            case GravityFlags.Top:
                y = PaddingTop + r.Height()/2;
                break;
            case GravityFlags.Bottom:
                y = Height - r.Height()/2 - PaddingBottom;
                break;
            default:
                y = Height / 2f + r.Height() / 2f - r.Bottom;
                break;
            }
            switch (Settings.Gravity)
            {
            case GravityFlags.Left:
                x = PaddingLeft + r.Width()/2;
                break;
            case GravityFlags.Right:
                x = Width - r.Width()/2 - PaddingRight;
                break;
            default:
                x = Width/2;
                break;
            }

            // Draw unpressed
            DrawBackground(unpressedCanvas, bounds, fillBackPaint, strokeBackPaint);
            if(Settings.IsTextStroked)
                unpressedCanvas.DrawText(Text, x, y, strokePaint);
            unpressedCanvas.DrawText(Text, x, y, textPaint);

            // Change colors
            fillBackPaint.Color = Settings.StrokeColor;
            strokeBackPaint.Color = Settings.FillColor;
            strokePaint.Color = Settings.FillColor;
            textPaint.Color = Settings.IsTextStroked ? Settings.StrokeColor : Settings.FillColor;

            // Draw pressed
            DrawBackground(pressedCanvas, bounds, fillBackPaint, strokeBackPaint);
            if(Settings.IsTextStroked)
                pressedCanvas.DrawText(Text, x, y, strokePaint);
            pressedCanvas.DrawText(Text, x, y, textPaint);

            // Set images for states
            StateListDrawable states = new StateListDrawable();
            states.AddState(new int[] {Android.Resource.Attribute.StatePressed}, new BitmapDrawable(_pressedImage));
            states.AddState(new int[] {Android.Resource.Attribute.StateFocused}, new BitmapDrawable(_pressedImage));
            states.AddState(new int[] {Android.Resource.Attribute.StateSelected}, new BitmapDrawable(_pressedImage));
            states.AddState(new int[] { }, new BitmapDrawable(_unpressedImage));
            SetBackgroundDrawable(states);

            strokePaint.Dispose();
            textPaint.Dispose();
            strokeBackPaint.Dispose();
            fillBackPaint.Dispose();
            unpressedCanvas.Dispose();
            pressedCanvas.Dispose();
        }
Exemplo n.º 14
0
        public static ImageView CreateMultipleTransitionImage(TransitionEffectType efType, Context c)
        {
            ImageView toReturn = new ImageView (c);
            ImageView emptyTrImage = new ImageView (c);
            emptyTrImage.SetImageResource (Resource.Drawable.emptytransition);
            int transitionCount = CountTransitionEffects (efType);
            string nsText = transitionCount < 10 ? transitionCount.ToString () : "9+";

            Bitmap bitmap = Bitmap.CreateBitmap (emptyTrImage.Width, emptyTrImage.Height, Bitmap.Config.Rgb565);
            Canvas canvas = new Canvas (bitmap);
            Paint paint = new Paint ();
            paint.Color = Android.Graphics.Color.White;
            paint.StrokeWidth = 18f;
            paint.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.SrcOver)); // Text Overlapping Pattern
            canvas.DrawBitmap (bitmap, 0, 0, paint);
            canvas.DrawText (nsText, 10, 10, paint);

            toReturn.SetImageBitmap (bitmap);
            canvas.Dispose ();
            bitmap.Dispose ();

            return toReturn;
        }
Exemplo n.º 15
0
		void ExpandMap()
		{
#if USE_GLES2
			Bitmap newmap = Bitmap.CreateBitmap( fontmap.Width * 2, fontmap.Height * 2, Bitmap.Config.Argb8888 );
			Canvas canvas = new Canvas( newmap );
			canvas.DrawBitmap( fontmap, 0, 0, new Paint() );
			canvas.Dispose();
#else
			Bitmap newmap = new Bitmap( fontmap.Width * 2, fontmap.Height * 2 );

			Graphics g = Graphics.FromImage( newmap );
			g.DrawImage( fontmap, 0, 0, fontrect, GraphicsUnit.Pixel );
			g.Dispose();
#endif

			fontmap = newmap;
			fontrect = new Rectangle( 0, 0, fontmap.Width, fontmap.Height );

			foreach( KeyValuePair<uint, FontCharacter> chp in charmap )
			{
				FontCharacter ch = chp.Value;
				ch.u = (short)( 65536 * ch.x / fontrect.Width );
				ch.v = (short)( 65536 * ch.y / fontrect.Height );
				ch.uw = (short)( 65536 * ( ch.x + ch.width ) / fontrect.Width );
				ch.vh = (short)( 65536 * ( ch.y + ch.height ) / fontrect.Height );
				ch.uvs[0 * 2 + 0] = (float)ch.x / fontrect.Width + (float)ch.width / fontrect.Width;
				ch.uvs[0 * 2 + 1] = (float)ch.y / fontrect.Height + (float)ch.height / fontrect.Height;
				ch.uvs[1 * 2 + 0] = (float)ch.x / fontrect.Width + (float)ch.width / fontrect.Width;
				ch.uvs[1 * 2 + 1] = (float)ch.y / fontrect.Height;
				ch.uvs[2 * 2 + 0] = (float)ch.x / fontrect.Width;
				ch.uvs[2 * 2 + 1] = (float)ch.y / fontrect.Height + (float)ch.height / fontrect.Height;
				ch.uvs[3 * 2 + 0] = (float)ch.x / fontrect.Width;
				ch.uvs[3 * 2 + 1] = (float)ch.y / fontrect.Height;
			}

		}
Exemplo n.º 16
0
		public FontRenderer( string font, int width, int height )
		{
			string tmp;
			int location;
			if( Display.FileExists( font, out location ) ) {
				ttf = new TrueTypeFont( Display.FileReadAllBytes( location, font ), 0 );
			}
			else if( Display.FileExists( tmp = ("c:/windows/fonts/" + font), out location ) )
				ttf = new TrueTypeFont( Display.FileReadAllBytes( location, tmp ), 0 );
			else if( Display.FileExists( tmp = ("Content/fonts/" + font), out location ) )
				ttf = new TrueTypeFont( Display.FileReadAllBytes( location, tmp ), 0 );
			else if( Display.FileExists( tmp = ( "/usr/share/fonts/TTF/" + font ), out location ) )
				ttf = new TrueTypeFont( Display.FileReadAllBytes( location, tmp ), 0 );
			else
				throw new Exception( "Font not found:" + font );
			scalex = ttf.GetScaleForPixelHeight( width );
			scaley = ttf.GetScaleForPixelHeight( height );

			int lineGap;
			ttf.GetFontVMetrics( out ascent, out descent, out lineGap );
			line_height = (int)Math.Ceiling( ( lineGap + ( ascent - descent ) ) * scaley );
			ascent = (int)( ascent * scaley );
			descent = (int)( descent * scaley );

			fontrect = new Rectangle( 0, 0, 256, 256 );
#if !USE_GLES2
			fontmap = new Bitmap( 256, 256 );
			Graphics g = Graphics.FromImage( fontmap );
			Brush b = new SolidBrush( Color.FromArgb( 0 ) );
			g.FillRectangle( b, fontrect );
			g.Dispose();
#else
			fontmap = Bitmap.CreateBitmap( 256, 256, Bitmap.Config.Argb8888 );
			Canvas canvas = new Canvas( fontmap );
			canvas.DrawColor( Android.Graphics.Color.Transparent );
			canvas.Dispose();
#endif
			charmap = new Dictionary<uint, FontCharacter>();

			line_heights = new List<int>();
			line_heights.Add( -1 );
			line_offsets = new List<int>();
			line_offsets.Add( 0 );

			Display.OnInvalidate += Display_OnInvalidate;
		}
Exemplo n.º 17
-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;
		}