缩放ImageView的图像,同时保持在同一个地方的中心点 [英] Scaling image of ImageView while maintaining center point in same place

查看:240
本文介绍了缩放ImageView的图像,同时保持在同一个地方的中心点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了prescaled位图的ImageView源。然后,我读过的矩阵的ImageView 并通过 matrix.postTranslate(shiftX,缩骨)转向了ImageView的位图

I have set a prescaled Bitmap as ImageView's source. Then I've read Matrix of an ImageView and shift Bitmap of an ImageView via matrix.postTranslate(shiftX, shiftY).

现在我要放大/缩小和形象,同时保持的ImageView 的中心位图的相同点是规模之前。

Now I want to zoom in / out and image while maintaining center of ImageView at the same point of Bitmap that was before scale.

如果我尝试在图片放大与 matrix.postScale(变焦,变焦),点,我想保持(蓝点)转移到其他地方(紫点)。

If I try to zoom in an image with matrix.postScale(zoom, zoom), point that I want to maintain (blue dot) shifts to other place (purple dot).

我已经尝试了几种不同的方法来移位图回来,但我不能让它正常工作。我知道,最初的位图大小,ImageView的大小,特点是点线的距离。试图计算需要移位,并使用 matrix.postTranslate(-zoomshiftX,-zoomshiftY)之后,但它不能正常移动。

I have tried several different ways to shift Bitmap back, but I cant get it to work correctly. I know initial Bitmap size, ImageView size, distances marked by doted line. Tried to calculate needed shift and use matrix.postTranslate(-zoomshiftX, -zoomshiftY) afterwards, but it doesn't shift correctly.

即使发现了,matrix.postScale()函数后潜在的位图的像素数并没有改变,并试图matrix.postTranslate(-zoomshiftX /变焦,-zoomshiftY /缩放) - 但仍没有运气

Even found out, that underlying Bitmap's pixel count doesnt change after matrix.postScale() function and tried matrix.postTranslate(-zoomshiftX/zoom, -zoomshiftY/zoom) - but still no luck.

我如何实现这种放大?

推荐答案

看看我的问题就在这里建立一个可缩放的ViewGroup。我所描述的code段从我的端到端解决方案,以及它的一些可能会有所帮助。

Take a look at my question here regarding creating a zoomable ViewGroup. I've described code snippets from my end solution, and some of it might be helpful.

<一个href="http://stackoverflow.com/questions/6378904/extending-relativelayout-and-overriding-dispatchdraw-to-create-a-zoomable-view/6490515#6490515">Extending RelativeLayout的,并覆盖dispatchDraw()创建一个可缩放的ViewGroup

这篇关于缩放ImageView的图像,同时保持在同一个地方的中心点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆