Reputation: 4906
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!
Upvotes: 0
Views: 1150
Reputation: 8390
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();
}
Upvotes: 2
Reputation: 32271
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);
}
Upvotes: -1