【发布时间】:2016-12-12 12:45:48
【问题描述】:
我的图像文件很大,接近 16MB。我想在我的 imageView 中加载此图像并在添加标记后对其进行缩放。我用 subsampling-scale-image-view 进行了尝试。我正在关注以下链接 https://github.com/davemorrissey/subsampling-scale-image-view 。
重要的是我正在从 url 加载图像。上面的库不支持。所以我只是下载了图像并在从该本地文件加载后保存到 SD 卡。从技术上讲,这是可行的。
问题:
现在的问题是第一次下载花费了太多时间。甚至第二次也需要将近一分钟。
我的想法:
由于这个问题,我尝试逐字节加载图像。一旦图像下载 100 字节,然后在 imageView 中显示下一个从 url 下载图像的下一部分。有可能这样做吗?
目前我正在加载类似以下代码的图像:
URL url = new URL(url_);
URLConnection conection = url.openConnection();
conection.connect();
// getting file length
int lenghtOfFile = conection.getContentLength();
// input stream to read file - with 8k buffer
InputStream input = new BufferedInputStream(url.openStream(), 8192);
// Output stream to write file
OutputStream output = new FileOutputStream(root+"/"+ fileName);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// writing data to file
output.write(data, 0, count);
}
// flushing output
output.flush();
// closing streams
output.close();
input.close();
runOnUiThread(new Runnable() {
@Override
public void run() {
image.setImage(ImageSource.uri(root+"/"+ fileName));
}
});
谁能帮我解开这个谜题?
注意: 如果除了这个库之外还有其他可能性,请添加您的建议。
【问题讨论】:
-
它来自API吗?我的意思是图片
-
是的,它来自 API
-
请php开发者将图片转成timthumb或mthumb格式
-
那不可能检查我的问题。我想缩放该图像并在其中添加标记。所以我不能用拇指。
-
我想你是直接从服务器加载文件的,为什么加载图像需要时间,只需将图像转换为 timthmub 然后你可以传递高度、宽度和质量然后得到你想要的图像质量