我需要将jpeg图像添加到firestore db记录中.我喜欢的方式是在Blob中,就像我在Sqlite记录中使用的那样.我在尝试这个时遇到了一些问题.以下是迄今为止我最好的尝试:
public Blob getImage() {
Uri uri = Uri.fromFile(new
File(mCurrentPhotoPath));
File f1 = new File(mCurrentPhotoPath);
URL myURL = null;
try {
myURL = f1.toURI().toURL();
} catch (MalformedURLException e) {
e.printStackTrace();
}
Bitmap bitmap = null;
BitmapFactory.Options options = new
BitmapFactory.Options();
options.inPreferredConfig =
Bitmap.Config.ARGB_8888;
try {
if (myURL != null) {
bitmap =
BitmapFactory.decodeStream(
myURL.openConnection().getInputStream());
String wBlob =
encodeToBase64(bitmap,
Bitmap.CompressFormat.JPEG, 100);
blob = fromBase64String(wBlob);
}
} catch (java.io.IOException e) {
e.printStackTrace();
}
return blob;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是在
blob = fromBase64String(wBlob);
将blob传递给设置记录的类也有问题.intent.putExtra("blobImage",blob); …