In my Android app I have an image that loads in. With this image the user can zoom in, out, and move it back and forth. Currently I can only get one to work at a time.
After a lot of testing I have determined that whatever I c开发者_开发知识库all second is the one that works.
matrix.setScale(zoom, zoom); // this will not work
matrix.setTranslate(currentX, currentY); // this will work
canvas.drawBitmap(image, matrix, null);
If I ran all the same code but simply switched setScale second it would then work but setTranslate wont.
This seems like it should be a simple answer. BTW: with the way my code is set up using post will not be practical.
matrix.postScale();
matrix.postTranslate();
Thanks in advance
When you call any of the set*() method you replace the entire content of the Matrix. In your first example, only setTranslate() is taken into account. You need to use the pre*() and post*() methods to combine the translate and scale operations.
Response code Romain
matrix.setScale(zoom, zoom); // this will not work
matrix.postTranslate(currentX, currentY); // this will work
canvas.drawBitmap(image, matrix, null);
精彩评论