【发布时间】:2015-08-31 18:42:48
【问题描述】:
我从 API 获取图像作为 BLOB 类型。而且,我保存如下,
public static void setOptimalImage(Context ctx, File file, ImageView iv,
Point size) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getPath(), options);
if (options.outHeight > 0 && options.outWidth > 0) {
if (size == null) {
size = new Point();
WindowManager wm = (WindowManager) ctx
.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getSize(size);
}
options.inSampleSize = Utils.calculateInSampleSize(options, size.x,
size.y);
options.inJustDecodeBounds = false;
try {
iv.setImageBitmap(BitmapFactory.decodeFile(file.getPath(),
options));
} catch (OutOfMemoryError oome) {
Log.e(Utils.class.getName(),
oome.getMessage() == null ? "OutOfMemory error: "
+ file.getName() : oome.getMessage());
}
}
}
现在,我面临的问题是,
当我保存它时,有时图像只保存了一半。现在,我的问题是,
- 有什么方法可以检查文件路径中的图像是否加载一半(这意味着已损坏)?
编辑:
- 我正在从服务器下载图像。与此同时,我失去了我的网络连接。在这种情况下,我的图像正在下载一半。我可以以编程方式获取那些损坏的图像吗?或者知道在这种情况下如何处理?
任何帮助将不胜感激。
谢谢。
附上图片供参考:
【问题讨论】:
-
@Manu 图片保存后需要刷新图库stackoverflow.com/questions/15837485/…刷新后需要设置图片