使用Glide缩放和遮罩 [英] Zoom and Mask using Glide

查看:731
本文介绍了使用Glide缩放和遮罩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想看看是否有人可以向我指出正确的方向,以学习如何使用Glide来实现这一目标...

I'm just looking to see if anyone can point me in the right direction to learning how to accomplish this using Glide...

  • 我们有一个包含内容的页面.

  • We have a page with content.

内容显示为单个图像(认为:杂志页面的图像)

Content is displayed as a single image (think: image of magazine page)

在轻松阅读模式下,我想居中并缩放第一行 文字内容并遮盖其余部分

In easy reading mode, I want to center and zoom on the first block of text content and mask the rest

单击下一个"时,我想移至下一个文本块 内容,最近更新和缩放

When 'next' is clicked, I want to move to the next block of text content, recenter and rezoom

单击后退"时,我想移至上一个文本块 内容,最近更新和缩放

When 'back' is clicked, I want to move to the previous block of text content, recenter and rezoom

蒙版将始终为矩形,但尺寸会不断变化以适合内容

the mask will always been rectangular but the size will constantly change to fit the content

我在下面放了几个简单的图像来说明我的意思.我们目前正在使用imageview和我们定位的4个黑色视图来执行此操作,但是它非常过时并且容易出现未对齐的情况.我们可以在Glide中完成此任务吗?

I've put a couple of simple images below to show what I mean. We're currently doing this with an imageview and 4 black views that we position but it's very janky and prone to misalignments. Can we accomplish this in Glide?

谢谢!

推荐答案

缩放和蒙版功能可以通过两种方式实现.对于蒙版图像,请使用 Glide ;对于缩放,请使用

Zoom and Mask function can be achieve in two ways. For masking the image use Glide and for zoom use PhotoView but as you mentioned that text content need to be zoom automatically then its complicated with the method you are following.

Glide为您提供了一种功能,可以自动将其在缓存和内存中保存的图像大小限制为ImageView尺寸,例如,如果图像不应该自动适合ImageView,请调用override(horizo​​ntalSize,verticalSize).在将其显示在ImageView中之前,将调整图像的大小.

Glide gives you a functionality that you automatically limits the size of the image it holds in cache and memory to the ImageView dimensions like if the image should not be automatically fitted to the ImageView, call override(horizontalSize, verticalSize). This will resize the image before displaying it in the ImageView.

GlideApp  
  .with(context)
  .load("Image resource")
  .override(600, 200) // resizes the image to these dimensions (in pixel). resize does not respect aspect ratio
  .into(imageView);

在没有已知尺寸的目标视图的情况下加载图像时,此选项也可能很有用.例如,如果该应用想要预热初始屏幕中的缓存,则它尚无法测量ImageViews.但是,如果您知道图像应该有多大,请使用override()提供特定的大小.从此处

This option might also be helpful when you load images when there is no target view with known dimension yet. For example, if the app wants to warm up the cache in the splash screen, it can't measure the ImageViews yet. However, if you know how large the images should be, use override() to provide a specific size. Check the other functions of Glide from here

使用PhotoView进行放大和缩小,甚至最适合您的情况(杂志页面).可以通过在滑动 .into()函数

Use PhotoView for zoom in and zoom out and even it's best for working in your scenario (magazine page). It can be attain by passing photoview instance as argument in glide .into() function

还请检查此示例

这篇关于使用Glide缩放和遮罩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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