Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将服务器映像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

复制
相关文章
Roslyn 分析器 EnforceExtendedAnalyzerRules 属性的作用
在开始编写 dotnet 的 Roslyn 分析器项目时,会被 VisualStudio 通过 RS1036 要求在项目文件配置上 EnforceExtendedAnalyzerRules 属性,本文将和大家介绍 EnforceExtendedAnalyzerRules 属性的作用
林德熙
2023/06/18
5160
Grid布局 项目属性
grid-row属性:grid-row-start和grid-row-end的简写形式。
赤蓝紫
2023/03/02
4200
Grid布局 项目属性
Grid布局 容器属性(二)
grid-auto-flow属性指定在网格中被自动布局的元素怎样排列。默认值是row,即先行后列。
赤蓝紫
2023/03/02
6940
Grid布局 容器属性(二)
【CSS】布局属性:display
p元素默认是换行的,加上inline-block属性之后,变成了一行,并且可以设置宽高和边距。
毛大姑娘
2021/04/25
1.5K0
Android布局属性详解
RelativeLayout用到的一些重要的属性: 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layout_centerVertical 垂直居中 android:layout_centerInparent 相对于父元素完全居中 android:layout_alignParentBottom 贴紧父元素的下边缘 android:layout_alignParentLeft 贴紧父元素的左边缘 andr
Angel_Kitty
2018/04/08
9740
flex 弹性布局常用属性
flex 是 Flexible Box 的缩写, 意为弹性布局。用来为盒状模型提供最大的灵活性,任何一个容器都可以指定为 Flex 布局
很酷的站长
2022/12/28
5180
flex 弹性布局常用属性
【CSS】布局属性:float
拿到一张设计稿,最先想到的就是如何布局。 垂直布局?水平布局?悬浮?层叠样式? 今天我们来复习一下CSS原生的布局属性——float。 float 浮动属性。 浮动是指元素悬浮在其他元素的上方,靠左或靠右排列; 浮动元素会避开其他元素的可视内容区域; 浮动元素可以是任何元素类型,可以设置margin来控制浮动元素与其他元素内容之间的距离; 被设置了float的元素无法使用left、top、right、bottom等位置属性(不生效)。 float:left; 元素向左浮动。 当前元素向左向上浮动,非浮动元素
毛大姑娘
2021/04/25
1.3K0
【CSS】布局属性:float
【CSS】布局属性:position
前面说到,被设置了float的元素无法使用left、top、right、bottom等位置属性。 那么什么情况下可以用位置属性呢?
毛大姑娘
2021/04/26
5590
【CSS】布局属性:Flex
Flex布局的出现是为了弥补float、position等布局属性的不足(比如控制多个子元素的排列方式)。
毛大姑娘
2021/05/06
8660
【CSS】布局属性:Flex
window10 python 3.6.8 本地 OCR 模块 muggle_ocr 安装实践
模块介绍地址:https://pypi.org/project/muggle-ocr/1.0/#description
卓越笔记
2023/02/18
1.7K0
jar中没有主清单属性啥意思啊_java没有主清单属性
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
全栈程序员站长
2022/10/04
1.9K0
flex弹性布局没有生效
注意,display:flex  一定要写在display:-webkit-flex;的后面 ,否则webview以及浏览器等都是webkit的内核会默认走
蓓蕾心晴
2019/11/13
1.7K0
CSS布局:完全掌握position属性
position属性是CSS中非常重要的布局属性,可以用来实现多种复杂的效果,如悬浮导航、弹性盒子、响应式布局等。理解并掌握不同类型的定位相对关系是熟练使用position属性的关键。
很酷的站长
2023/10/07
3840
CSS布局:完全掌握position属性
CSS 弹性布局 flex 属性详解
定义了当flex容器有多余空间时,item是否放大。默认值为0,即当有多余空间时也不放大;可能的值为整数,表示不同item的放大比例,如
一个会写诗的程序员
2018/08/17
3440
CSS 弹性布局 flex 属性详解
.jar中没有主清单属性[通俗易懂]
问题:xxx.jar中没有主清单属性 背景:maven项目,springboot服务    IDEA打包,jar包运行出现上述错误
全栈程序员站长
2022/10/04
3.8K0
.jar中没有主清单属性[通俗易懂]
jar中没有主清单属性
我今天遇到了一个报错… 我仔细一看发现jar包才893KB大小 检查了一下打包配置,发现: 这块少了个repackage配置… <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> </execution> </executions> 加上就可以了 再次打包就好了
阿超
2022/08/21
2.3K0
jar中没有主清单属性
Grid布局 容器属性(一) `grid-template`系列属性
如果学会语法了,想要类似刷题增加一点印象的话,可以去GRID GARDEN玩一下游戏,不过比较简单。
赤蓝紫
2023/03/16
1.9K0
Grid布局 容器属性(一) `grid-template`系列属性
最好用的ocr识别工具,没有之一!
小编从来都是雨露均沾,让mac系统的小伙伴酸了那么久,今天必须安排一个神器——OCR文字识别工具。
BigYoung小站
2020/07/21
6.4K1
最好用的ocr识别工具,没有之一!
iOS动画-CALayer布局属性详解
本篇主要内容: 1.Frame与Bounds的区别 2.中心点(position)与锚点(anchorPoint) 3.视图与图层的坐标系
梧雨北辰
2019/04/23
2.3K0
iOS动画-CALayer布局属性详解
CSS布局-display属性 block 和 inblock
## 简介 display属性是控制网页布局非常重要的css属性。 display属性规定如何显示元素,每个html的元素都有一个默认的display值,一般为block或inline。 **块级元素(block element)** 块级元素总是从新行开始,并占据可用的全部宽度(尽可能向左和向右伸展)。 ``` 比如:<div>、<h1> - <h6>、<p>、<form>、<header>、<footer>、<section> ``` **行内元素(inline element)** 内联元素不从新的一行开始,根据实际宽度占有页面宽度。通过将 **display** 属性设置为 **none** 可以隐藏元素。该元素将被隐藏,并且页面将显示为好像该元素不在其中。 ``` 比如<span>、<a>、<img> ``` **Display: none** **display: none;** 通常与 JavaScript 一起使用,以隐藏和显示元素, {visibility:hidden}可以隐藏元素,但仍占有空间,影响布局。 **覆盖默认的 Display 值** 如前所述,每个元素都有一个默认 display 值。但是,您可以覆盖它。 将行内元素更改为块元素,反之亦然,对于使页面以特定方式显示同时仍遵循 Web 标准很有用。 <hr class="content-copyright" style="margin-top:50px" /><blockquote class="content-copyright" style="font-style:normal"><p class="content-copyright">版权属于:Cyril</p><p class="content-copyright">本文链接:<a class="content-copyright" href="https://www.cyrilstudio.top/archives/578/">https://www.cyrilstudio.top/archives/578/</a></p><p class="content-copyright">转载时须注明出处及本声明</br></br><span class="external-link"><a class="no-external-link" href="https://cyrilstudio.top/" target="_blank">技术交流,软件开发,网站建设,资源下载,设计开发,编程学习<i data-feather='external-link'></i></a></span></br><span class="external-link"><a class="no-external-link" href="http://hackeros.ink/" target="_blank">点此访问设计师专用导航网址<i data-feather='external-link'></i></a></span></p></blockquote>
梦溪
2021/08/25
9200

相似问题

AttributeError:模块“ocrmypdf”没有属性“ocr”

15

没有名为'Ocr‘的模块

353

警告: autodoc:未能导入模块'OCR';引发以下异常:没有名为'OCR‘的模块

10

AttributeError:“str”对象没有“”get“”ocr属性“”

12

如何安装Nativescript OCR模块

14
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

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

洞察 腾讯核心技术

剖析业界实践案例

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