dimanche 3 juillet 2016

Save Canvas after .drawPath as .png

I explain better my issue: I need to draw a path in a .png like this, and I need to do this in a responsive way, so I figured out that the "best" way would be to work (write path) directly on the source image, save this new image and after this recall the new image with path and do the appropriate scaling. What's the best way to accomplish that in Android (Canvas,Bitmap)? For now the "best" solution that I turned out is to create a Bitmap with the original .png and do the draw in Canvas, the problem is that I cannot scale the canvas.

public class FloorImageView extends ImageView {

    /*
     * all variables used (context, image, path etc...)
     */

    public FloorImageView(Context context, AttributeSet attrs) {
        super(context, attrs);

        setFocusable(true);
        setVerticalScrollBarEnabled(true);

        setFocusableInTouchMode(true);
        setBitmap();

        lineStylePaint(); // set drawPaint
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        canvas.drawBitmap(image,0,0,drawPaint);
        canvas.drawPath(path, drawPaint); // I convert dpi to pixel
    }


    private void setBitmap(){
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inMutable = true;
        image = BitmapFactory.decodeResource(getContext().getResources(),R.drawable.q145,options);
    }
    /*
     * Other ImageView code
     */
}

Aucun commentaire:

Enregistrer un commentaire