【发布时间】:2018-03-13 21:11:38
【问题描述】:
我需要将 JPEG 图像添加到 Firestore 数据库记录。我首选的方式是在 SQLite 记录中使用的 blob 中。我在尝试这个时遇到了一些问题。
这是我迄今为止最好的尝试:
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;
}
我的问题是:
blob = fromBase64String(wBlob);
我在将 blob 传递给设置记录的类时也遇到了问题:
intent.putExtra("blobImage", blob );
【问题讨论】:
标签: java blob jpeg google-cloud-firestore