How to keep BitmapShader not drawing outside the image

598 views Asked by At

I have a custom view that is showing an image inside a shape. I used BitmapShader to fit my image into the shape with TileMode is CLAMP Now I have a problem that when I am moving my image (using setLocalMatrix method) it make my image become terrible. here is my image when moving around: enter image description here

Here is my code:

BitmapShader shader=new BitmapShader(sbmp, TileMode.CLAMP, TileMode.CLAMP);
Matrix currMatrix = new Matrix(this.getMatrix());
currMatrix.postTranslate(currX, currY); 
shader.setLocalMatrix(currMatrix);
mpaint.setShader(shader);
1

There are 1 answers

0
Drake29a On

You can translate image with instead of localMatrix

int i = canvas.save();
canvas.translate(currX, currY);
//Here draw image
canvas.restoreToCount(i);