Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何将服务器映像url转换为可绘制的Int

如何将服务器映像url转换为可绘制的Int
EN

Stack Overflow用户
提问于 2021-01-31 21:17:18
回答 1查看 78关注 0票数 3

我在服务器上有图像,并使用毕加索库将其加载到安卓应用程序中,我希望ZoomIn和缩放应用程序中所有加载的图像。我推荐https://developer.android.com/training/animation/zoom#java这个链接来放大imageView。

在下面的代码中,调用zoomImageFromThumb时,它们传递的是ImageView持有人和可绘制int。

请帮助我转换图像URl到绘图Int作为参数传递,也请让我知道是否有任何其他解决方案。

提前感谢

加载图像代码

代码语言:javascript
运行
AI代码解释
复制
Picasso.get()
.load(model.getImage_path())
        .error(R.drawable.not_found)
        .into(image_IV)

调用zoomImageFromThumb

代码语言:javascript
运行
AI代码解释
复制
        thumb1View.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                zoomImageFromThumb(thumb1View, R.drawable.image1);
            }
        });````
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-31 21:32:50

他们将drawableId作为Int,并将其设置为ImageView中的image,但在您的示例中,您可以使用picassoimage加载到Imageview中,这样您就可以将url而不是drawableId传递到zoomImageFromThumb方法,如下所示

代码语言:javascript
运行
AI代码解释
复制
 private fun zoomImageFromThumb(thumbView: View, imageUrl: String) {
        // If there's an animation in progress, cancel it
        // immediately and proceed with this one.
        currentAnimator?.cancel()

        //load image using picasso
        Picasso.get()
        .load(imageUrl)
        .error(R.drawable.not_found)
        .into(findViewById<ImageView>(R.id.expanded_image))
    
        // Calculate the starting and ending bounds for the zoomed-in image.
        // This step involves lots of math. Yay, math.
        val startBoundsInt = Rect()
        val finalBoundsInt = Rect()
        val globalOffset = Point()
    
        // The start bounds are the global visible rectangle of the thumbnail,
        // and the final bounds are the global visible rectangle of the container
        // view. Also set the container view's offset as the origin for the
        // bounds, since that's the origin for the positioning animation
        // properties (X, Y).
        thumbView.getGlobalVisibleRect(startBoundsInt)
        findViewById<View>(R.id.container)
                .getGlobalVisibleRect(finalBoundsInt, globalOffset)
        startBoundsInt.offset(-globalOffset.x, -globalOffset.y)
        finalBoundsInt.offset(-globalOffset.x, -globalOffset.y)
    
        val startBounds = RectF(startBoundsInt)
        val finalBounds = RectF(finalBoundsInt)
    
        // Adjust the start bounds to be the same aspect ratio as the final
        // bounds using the "center crop" technique. This prevents undesirable
        // stretching during the animation. Also calculate the start scaling
        // factor (the end scaling factor is always 1.0).
        val startScale: Float
        if ((finalBounds.width() / finalBounds.height() > startBounds.width() / startBounds.height())) {
            // Extend start bounds horizontally
            startScale = startBounds.height() / finalBounds.height()
            val startWidth: Float = startScale * finalBounds.width()
            val deltaWidth: Float = (startWidth - startBounds.width()) / 2
            startBounds.left -= deltaWidth.toInt()
            startBounds.right += deltaWidth.toInt()
        } else {
            // Extend start bounds vertically
            startScale = startBounds.width() / finalBounds.width()
            val startHeight: Float = startScale * finalBounds.height()
            val deltaHeight: Float = (startHeight - startBounds.height()) / 2f
            startBounds.top -= deltaHeight.toInt()
            startBounds.bottom += deltaHeight.toInt()
        }
    
        // Hide the thumbnail and show the zoomed-in view. When the animation
        // begins, it will position the zoomed-in view in the place of the
        // thumbnail.
        thumbView.alpha = 0f
        expandedImageView.visibility = View.VISIBLE
    
        // Set the pivot point for SCALE_X and SCALE_Y transformations
        // to the top-left corner of the zoomed-in view (the default
        // is the center of the view).
        expandedImageView.pivotX = 0f
        expandedImageView.pivotY = 0f
    
        // Construct and run the parallel animation of the four translation and
        // scale properties (X, Y, SCALE_X, and SCALE_Y).
        currentAnimator = AnimatorSet().apply {
            play(ObjectAnimator.ofFloat(
                    expandedImageView,
                    View.X,
                    startBounds.left,
                    finalBounds.left)
            ).apply {
                with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top))
                with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f))
                with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f))
            }
            duration = shortAnimationDuration.toLong()
            interpolator = DecelerateInterpolator()
            addListener(object : AnimatorListenerAdapter() {
    
                override fun onAnimationEnd(animation: Animator) {
                    currentAnimator = null
                }
    
                override fun onAnimationCancel(animation: Animator) {
                    currentAnimator = null
                }
            })
            start()
        }
    
        // Upon clicking the zoomed-in image, it should zoom back down
        // to the original bounds and show the thumbnail instead of
        // the expanded image.
        expandedImageView.setOnClickListener {
            currentAnimator?.cancel()
    
            // Animate the four positioning/sizing properties in parallel,
            // back to their original values.
            currentAnimator = AnimatorSet().apply {
                play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left)).apply {
                    with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                    with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale))
                    with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale))
                }
                duration = shortAnimationDuration.toLong()
                interpolator = DecelerateInterpolator()
                addListener(object : AnimatorListenerAdapter() {
    
                    override fun onAnimationEnd(animation: Animator) {
                        thumbView.alpha = 1f
                        expandedImageView.visibility = View.GONE
                        currentAnimator = null
                    }
    
                    override fun onAnimationCancel(animation: Animator) {
                        thumbView.alpha = 1f
                        expandedImageView.visibility = View.GONE
                        currentAnimator = null
                    }
                })
                start()
            }
        }
    }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65987512

复制
相关文章
python: ValueError:
File "/self/_UDACity/pythonLearning/mathTest.py", line 28, in <module>     tmp3 = math.log((1/3), 2)# ValueError: math domain error
py3study
2020/01/08
7120
【说站】python元组如何打包和解包
2、解包时,如果解包出来的元素数目与变量数目不匹配,就会引发ValueError异常。
很酷的站长
2022/11/23
8170
【说站】python元组如何打包和解包
Python - 解包的各种骚操作
https://www.cnblogs.com/poloyy/p/14658433.html
小菠萝测试笔记
2021/08/10
6600
Python抛出异常_python抛出异常的作用
在python中不同的异常可以用不同的类型(python中统一了类与类型,类型即类)去标识,不同的类对象标识不同的异常,一个异常标识一种错误
全栈程序员站长
2022/11/02
2.6K0
文件打包解包的方法
在很多情况下,软件需要隐藏一些图片,防止用户对其更改,替换。例如腾讯QQ里面的资源图片,哪怕你用Everything去搜索也搜索不到,那是因为腾讯QQ对这些资源图片进行了打包,当软件运行的时候解包获取资源图片。
DeROy
2020/05/12
2.1K1
Python有趣的解包用法
python中的解包可以这样理解:一个list是一个整体,想把list中每个元素当成一个个个体剥离出来,这个过程就是解包,我们来看下面这些例子(分为10个部分)。
Python中文社区
2018/07/26
8480
dotnet C# 应用程序进程创建太多线程将会抛出 OutOfMemoryException 异常
本文记录一个 dotnet 的特性,在应用程序快速创建大量线程的时候,将会因为线程创建时没有足够的资源而创建失败,此时将会抛出 OutOfMemoryException 异常,但实际进程占用内存不多
林德熙
2021/09/23
9900
matplotlib无法显示图片_pycharm不出图
首先你运行之后最小化pycharm,看看是不是已经出来了,只是没有自己弹到最顶层。
全栈程序员站长
2022/09/25
2.2K0
matplotlib无法显示图片_pycharm不出图
Celery ValueError: n
最近因项目需要,在使用任务队列Celery的时候,出现如题错误,最终在github上里找到解决办法,记录一下。
py3study
2020/01/20
7980
【说站】python序列解包的使用
2、字典中使用序列解包时,默认情况下是键的操作。如果需要操作键值,则需要使用items(),如果需要操作值,则使用value()。
很酷的站长
2022/11/24
4650
【说站】python序列解包的使用
ValueError: too many
数据:{'O_DATA': [{'ACCOUNT': 'A20001002', 'ZACTOSP': Decimal('21792635.96'), 'ZBUDGET': Decimal('290271.50'), 'ZACTUAL': Decimal('4878563.10')}]}
py3study
2020/01/16
6860
ValueError: too many
ValueError:invalid
使用django的异步调用场景时,并配置了如下配置:出现了错误:ValueError: Database is int between 0 and limit - 1, not :6379/0
cywhat
2023/04/27
3830
Basemap工具函数(1)
添加一个经度值到经度数组中,并且添加一列值到数据数组中。当数据覆盖全部经度时,非常有利于添加缺省值。
bugsuse
2020/04/21
2.4K0
Basemap工具函数(1)
解决织梦CMS Tag中文字太多/太长失效无法添加的问题
最近老蒋看到群里网友在使用织梦CMS程序还是比较多的,尤其是有做范文类内容网站比较多,毕竟大数据网站是不适合WP这种程序的。不过在织梦CMS程序提交文章过程中,他们如果提交的TAG字符过长,或者中文字太多的话会会无法被写入数据库,这个是什么问题呢?
老蒋
2021/12/27
9970
深入Go:错误的包装与解包
仔细想想,我们的Go代码中可能有四分之一的代码都是和错误处理相关的,而我们已经接受了,error无处不在。但似乎Go的error处理并不够强大,也缺乏统一的错误处理流程的逻辑;在经历了大量的讨论后,Go 1.13引入了错误的包装和解包,也许某种程度上可以优化我们的错误处理流程。
wenxing
2021/12/14
2K0
Python 元组解包的几种方法
要将一个tuple中的所有值作为参数,如果直接用上面两种方法就不太 pythonic了,可以用以下方法解包
Ewdager
2020/07/14
1.4K0
maven 解包依赖项中的文件
使用goal:unpack-dependencies 在配置参数includeArtifactIds中指定要解包的模块制件ID
路过君
2022/07/20
2.5K0
工具推荐|pyinterp-面向地球科学领域的插值工具
此项目的动机是为地球科学领域提供插值工具。当然也有其它库可应用于地球科学的数据插值,但是这些库基本完全是用Python编写,其性能无法满足需求。
bugsuse
2022/09/23
9800
工具推荐|pyinterp-面向地球科学领域的插值工具
Python可视化 | 三维图形迁移
在前面推送中我们提到了通过collection功能而在3D地图中添加地图的方法,也短暂提到了栅格与填色两种图形样式的降维方法。但是从matplotlib这两个函数的底层有一定的局限性,比如下面这两张图的侧面填色就无法绘出:
郭好奇同学
2021/05/28
1.9K0
Python可视化 | 三维图形迁移
自动美化你的Matplotlib ,使用Seaborn控制图表的默认值
如果您曾经在 Python 中进行过数据可视化,那么很可能您使用了 Matplotlib 库。这个库包含了许多绘图的功能。但是一些概念上简单的可视化需要大量的代码才能完成。而在这个时代,人们希望能够与图表进行交互——这是普通 Matplotlib 库无法提供的功能。更重要的是,采用默认设置的 Matplotlib 图表通常看起来很糟糕。
deephub
2020/06/04
1.7K0

相似问题

如何根据熊猫数据帧中的数据类型填写NaN值?

12

未知的帧大小

11

块大小未知的示例dask数据帧

129

如何填写熊猫丢失的GPS数据?

22

熊猫费()填写丢失的数据

26
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档