panpf / zoomimage

ZoomImage is a library designed for Compose Multiplatform and Android View for gesture zoom viewing of images, supported scale, pan, locate, rotation, and super-large image subsampling.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

有办法切换图片的时候 保持原本的缩放和移动吗?

leeManong opened this issue · comments

想实现个效果,先展示的缩略图,用户双指放大后自动加载原图,能做到原图加载设置好后,还保持之前的缩放和移动吗?

这很难,因为有很多计算需要依赖 contentSize,也就是加载到内存的图片的尺寸,contentSize 改变了就必须要重置所有的缩放信息

你可以尝试将现在组件的源码复制一份,然后将 contentSize 设置为 和 containerSize 一样,看看效果

另外我想知道你是什么样的业务场景会有这样的需求

你的想法很难实现,你只能按我刚才说的办法试试了

这个代码是可以保持前后两张图的 看上去没有区别的,直接用原来的transformState替换到新的上。
有个问题就是替换后,手指去触摸缩放时会不太对。
如果能提供个setImageNoReset()就好啦。

val value = binding.imageView.zoomable.transformState.value.copy()
            Glide.with(this)
                .load("http://:www....")
                .into(object :SimpleTarget<Drawable>(){
                    override fun onResourceReady(
                        resource: Drawable,
                        transition: Transition<in Drawable>?
                    ) {
                        Glide.with(this@MainActivity).load(resource).into(binding.imageView)
//                        binding.imageView.setImageDrawable(resource)
                        lifecycleScope.launch(Dispatchers.Main) {
                            delay(100)
                            binding.imageView.zoomable._transformState.value = value
                        }
                    }

                })