Android how do I zoom and scroll a bitmap which is created on the fly

拜拜、爱过 提交于 2019-12-04 18:56:44

There's a very simple ImageViewTouch that Sephiroto made based on the Gallery application code : http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/

I use it in a project and it works perfectly, with pinch-to-zoom and everything you might want. By default, when you set an image to it, the image will be scaled down to fit the screen.

edit : if you want to prevent the automatic image resize, you can change the ImageViewTouchBase.getProperBaseMatrix method to the following :

protected void getProperBaseMatrix(RotateBitmap bitmap, Matrix matrix) {
    float viewWidth = getWidth();
    float viewHeight = getHeight();
    float w = bitmap.getWidth();
    float h = bitmap.getHeight();
    matrix.reset();
    matrix.postConcat(bitmap.getRotateMatrix());
    matrix.postTranslate((viewWidth - w) / 2, (viewHeight - h) / 2);
}

This should center the image without resizing it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!