我从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());
}
}
}
现在我面临的问题是,
当我保存它时,有时图像只保存half.Now,我的问题是,
编辑:
任何帮助都会很感激的。
谢谢。
附加图像以供参考:
发布于 2015-09-03 08:28:21
我认为你发现了检测损坏图像的错误方向。使用API和请求管理加载(或半加载)位图很容易。您还可以拥有一个文件(或者更好的数据库),在该文件中您将获得有关下载图像的信息。
我看到多个检查,“是图像下载了吗?”
在显示期间,您可以检测哪些图像已完全加载。
发布于 2015-09-03 08:38:17
理想情况下,您应该让API返回每个文件的校验和(例如MD5)。然后,您可以使用Android中相同的算法为下载的文件生成校验和,并将其与从API返回的校验和进行比较。有关如何生成校验和的详细信息,请查看java.security.MessageDigest
类。
https://stackoverflow.com/questions/30859247
复制相似问题