【发布时间】:2016-01-31 11:38:04
【问题描述】:
我正在使用EasyImage图书馆拍照。
然后我将这些文件转换为位图,然后将位图转换为 Base64 并将其上传到服务器。
我知道,这不是一个好方法,但我目前就是这样做的。
拍照时:
@Override
public void onImagePicked(File imageFile, EasyImage.ImageSource source) {
uploadImage(imageFile);
}
这是“uploadImage”方法中的第一行:
Image image = new Image(LoginManager.getInstance(getApplicationContext()).getUsername(), file);
这是构造函数:
public Image(String userName, File imageFile) {
this.userName = userName;
this.imageFile = imageFile;
createBase64(getBitmap());
}
在“getBitmap”内部是问题开始的地方。尤其是这两行:
bitmap = BitmapFactory.decodeFile(imageFile.getPath());
bitmap = Bitmap.createScaledBitmap(bitmap, 100, 100, false);
imageFile 从不为空。
我用调试器检查了至少 100 次,它永远不会为空。它也总是有路径。getPath() 永远不会为空。
但是,它仍然经常无法创建位图。
有时它成功并且一切正常,但大多数时候,位图为空。
我不知道为什么。
文件(拍摄的照片)总是创建成功并且永远不会为空,但由于某种原因它无法创建位图。
【问题讨论】:
标签: android bitmap android-file