如何在图片的形状周围绘制轮廓?

时间:2020-06-17 15:59:04

标签: android matrix canvas bitmap scale

您可以在图片中看到,我想用箭头扩展显示的零件并绘制轮廓,有没有办法做到这一点?

我真正想做的是在背面扩展矩阵并在其上绘制普通图片。

Click to see the picture Click to see the picture

1 个答案:

答案 0 :(得分:0)

因此,以该自定义视图为例

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 );
    }
}