[英]Getting a uri from a bitmap
我正在嘗試從 bitmap 獲取 uri,以便我可以將其上傳到 Firebase 的存儲,但我的path
一直返回為 null。 經過一番谷歌搜索后,我嘗試將<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
添加到我的清單中以修復它,但它沒有任何效果。 每當我在 android 工作室調試我的程序時,它似乎在創建path
時中斷。
這是代碼:
private Uri getImageUri(Context inContext, Bitmap myImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
myImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), myImage, "Title", null);
return Uri.parse(path);
}
這是我如何使用該方法的示例
Uri file = getImageUri(getApplicationContext(), uploadPhoto);
StorageReference picRef = storageRef.child("images/" + file.getLastPathSegment());
// Uploads the file
UploadTask uploadTask = picRef.putFile(file);
如果您已經擁有 memory 中的圖像,為什么還需要對其在磁盤上的路徑的引用? 直接上傳圖片就好了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.