使用毕加索将从活动中的远程源获取的图像传递到另一个活动中 [英] passing image fetched from a remote source in an activity to another activity using picasso

查看:132
本文介绍了使用毕加索将从活动中的远程源获取的图像传递到另一个活动中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android开发的初学者.我有一组图像,使用Picasso从URL提取到活动"A"中,并排列在GridView中.现在,我想将用户点击的图像传递到一个Intent中.如何将获取的图像之一传递给另一个活动,而不必再次获取图像.

I'm a beginner in android development.I've a set images fetched from a URL into an Activity 'A' using Picasso, and are arranged in a GridView. Now, I want to pass the image which the user has tapped on, into an Intent. How can I pass the one of the fetched image to another activity, without having to fetch the image again.

请帮助我.

谢谢.

推荐答案

如果您尝试重用在ActivityB中从ActivityA中获取的图像而又没有再次获取,则除了调用之外,您无需做任何其他事情

If you are trying to reuse an image fetched in ActivityA in ActivityB without fetching again, you don't have to do anything apart from calling

Picasso.with(context).load(url).into(imageView)

在两个地方.

如果两个活动的 url 参数都相同,则毕加索会自动从缓存(当您在ActivityA中调用load时将其存储在其中)中获取图像,而不用进行另一个网络调用.

If the url parameter is the same for both the activities, Picasso automatically fetches the image from cache(where it got stored when you called load in ActivityA) instead of making another network call.

Picasso自动将您的映像缓存在RAM中,并在内部使用okhttp将该映像缓存在磁盘中.因此,您不必通过意图将其显式传递.

Picasso automatically caches your image in the RAM, and uses okhttp internally to cache it in the disk. So, you don't have to pass it explicitly through an intent.

要检查从何处加载,可以致电

To check where it got loaded from, you can call

Picasso.with(getContext()).setIndicatorsEnabled(true).

这将在每个图像的左上角放置一个彩色标记.

This will put a colored flag on the top-left corner of every image.

红色表示它是从网络提取的.

蓝色-磁盘.

绿色- RAM .

在ActivityA中,它应为红色,因为您是从网络中加载它的. 在ActivityB中,它应该是绿色(或蓝色),因为您是从缓存中获取它的.

In ActivityA, it should be Red since you're loading it from the network. In ActivityB, it should be Green(or blue), since you're fetching it from the cache.

这篇关于使用毕加索将从活动中的远程源获取的图像传递到另一个活动中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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