![](/img/trans.png)
[英]Subsampling scale image view - make pin markers clickable on Imageview
[英]How to load image from picasso to subsampling-scale-image-view..please can any one simplify this?
我想通过 picasso 库从 URL 加载图像到 android studio 中的 subsampling-scale-image-view。
我曾尝试过 picasso 解码器和 picasso 区域解码器,但它在 okhttp3downloader 客户端构造函数上出错。
public class PicassoRegionDecoder implements ImageRegionDecoder {
private OkHttpClient client;
private BitmapRegionDecoder decoder;
private final Object decoderLock = new Object();
public PicassoRegionDecoder (OkHttpClient client) {
this.client = client;
}
@Override
public Point init(Context context, Uri uri) throws Exception {
OkHttp3Downloader downloader=new OkHttp3Downloader(client);
//OkHttpDownloader downloader = new OkHttpDownloader(client);
InputStream inputStream = downloader.load(uri, 0).getInputStream();
this.decoder = BitmapRegionDecoder.newInstance(inputStream, false);
return new Point(this.decoder.getWidth(), this.decoder.getHeight());
}
@Override
public Bitmap decodeRegion(Rect rect, int sampleSize) {
synchronized(this.decoderLock) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = sampleSize;
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = this.decoder.decodeRegion(rect, options);
if(bitmap == null) {
throw new RuntimeException("Region decoder returned null bitmap - image format may not be supported");
} else {
return bitmap;
}
}
}
@Override
public boolean isReady() {
return this.decoder != null && !this.decoder.isRecycled();
}
@Override
public void recycle() {
this.decoder.recycle();
}
}
无法解析构造函数 OkHttpDownloader(client)
回答
子采样比例图像视图是一个“旧”帖子。
你必须小心进口,这些是有效的:
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.okhttp:okhttp:2.1.0'
现在,如果您想使用最近的库,请将您的代码片段更改为:
@Override
public Point init(Context context, Uri uri) throws Exception {
OkHttp3Downloader downloader = new OkHttp3Downloader(client);
okhttp3.Request request = new Request.Builder().url(uri.toString()).build();
InputStream inputStream = downloader.load(request).body().byteStream();
this.decoder = BitmapRegionDecoder.newInstance(inputStream, false);
return new Point(this.decoder.getWidth(), this.decoder.getHeight());
}
请在此处参考 DAVEMORRISSEY(开发人员)的帖子
https://gist.github.com/davemorrissey/e2781ba5b966c9e95539
并阅读评论
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.