Search code examples
androidmatrixcanvasbitmapscale

How to draw a contour around a shape in a picture?


As you can see in the picture, I want to expand the of the parts I show with arrows and draw a contour, is there a way to do this?

What I really want to do is expand the matrix on the back and draw the normal picture on it.

Click to see the picture Click to see the picture


Solution

  • So use this custom view as example

    enter image description here

    public class ViewHighLight extends View{
        final Bitmap bms; //source
        final Bitmap bmm; //mask
        final Paint paint;
        final int width = 4;
        final int color_highlight = 0xff00ff00;
        final int step = 15; // 1...45
    
        public ViewHighLight( Context context ){
            super( context );
            bms = BitmapFactory.decodeResource( getResources(), R.drawable.b );
            bmm = Bitmap.createBitmap( bms.getWidth(), bms.getHeight(), Bitmap.Config.ALPHA_8 );
            Canvas canvas = new Canvas( bmm );
            canvas.drawBitmap( bms,0,0, null );
            paint = new Paint( Paint.ANTI_ALIAS_FLAG );
            paint.setColor( color_highlight );
        }
    
        @Override
        protected void onDraw( Canvas canvas ){
            super.onDraw( canvas );
    
            // draw blur shadow
            for( int i = 0; i < 360; i+=step ){
                float x = width * (float)Math.cos( Math.toRadians( i ) );
                float y = width * (float)Math.sin( Math.toRadians( i ) );
                canvas.drawBitmap( bmm, x,y, paint );
            }
            //draw source bitmap on the top
            canvas.drawBitmap( bms, 0,0, null );
    
            //draw bitmap on the right for compare
            canvas.drawBitmap( bms, bms.getWidth(),0, null );
        }
    }