0

I'm looking to transform an image using a Matrix on the onDraw method of a custom class I created which extends ImageView e.g.,

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.save();
    canvas.setMatrix(imageMatrix);
    canvas.drawBitmap(((BitmapDrawable)mIcon).getBitmap(), imageMatrix, null);
    canvas.restore();
}

However, what I coded above does not really work. How exactly do I apply the imageMatrix on the canvas? Thanks!

2 Answers 2

2

Try calling Drawable.draw(Canvas) method:

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.save();
    canvas.setMatrix(imageMatrix);
    ((BitmapDrawable)mIcon).draw(canvas);
    canvas.restore();
}
Sign up to request clarification or add additional context in comments.

Comments

-1

All you did is good, just put the super call to be the last, coz there is where all the painting is done...

@Override
public void onDraw(Canvas canvas) {
    canvas.setMatrix(imageMatrix);
    super.onDraw(canvas);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.