1
我想在將圖片上傳到Firebase存儲之前調整大小。Android Firebase調整圖片大小並上傳到Firebase存儲
我的問題是:FireBase上傳基於它的Uri的圖像。 我從畫廊的意圖得到了圖像,並把它放在ImageView
和調整它的大小是這樣的:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent returnIntentData) {
super.onActivityResult(requestCode, resultCode, returnIntentData);
switch(requestCode) {
case RC_SELECT_PHOTO:
if (resultCode == RESULT_OK) {
mImageUri = returnIntentData.getData();
mSelectedImage.setImageURI(mImageUri);
//get a Image obj from ImageView
Bitmap bit = ((BitmapDrawable) mSelectedImage.getDrawable()).getBitmap();
int width = bit.getWidth();
int height = bit.getHeight();
float rate = 0.0f;
int maxResolution = 1920;
int newWidth = width;
int newHeight = height;
if(width > height) {
if(maxResolution < width) {
rate = maxResolution/ (float) width;
newHeight = (int) (height * rate);
newWidth = maxResolution;
}
} else {
if(maxResolution < height) {
rate = maxResolution/(float)height;
newWidth = (int) (width * rate);
newHeight = maxResolution;
}
}
Bitmap resizedImage = Bitmap.createScaledBitmap(bit, newWidth, newHeight, true);
mSelectedImage.setImageBitmap(resizedImage);
}
和火力上傳底座上的開放的我們像這樣(如果有其他的方式來上傳文件,它會如此有用):
public void uploadPhotoToStorage() {
//present image's Ref
StorageReference presentGymPhotoRef =
mGymStorageReferences.child(mImageUri.getLastPathSegment());
//Upload file to Firebase Storage
presentGymPhotoRef.putFile(mImageUri)
.addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUri = taskSnapshot.getDownloadUrl();
//save gymPhoto Uri to instance
gymPhotoUri = downloadUri.toString();
gymName = mEditGymName.getText().toString();
.......
有沒有什麼辦法讓Bitmap
的URI或ImageView
的URI?或者只是調整大小併成功上傳?
我是新畢加索,所以我d喜歡知道如何從ViewHolder的ImageView中獲取圖像的Uri。 我明白,畢加索將調整圖像大小,但我需要特定的Uri,這是調整大小的Imageview。和我知道如何訪問SD卡上的原始圖像文件或從Uri加載圖像但我不知道如何使Uri是調整大小的圖像。 – Jarvis
對不起,我剛剛收到此消息。爲什麼你需要調整圖像大小?畢加索允許您顯示調整大小的圖像,但是您是否需要存儲具有特定大小的圖像? – Anthony
,因爲我需要將圖像上傳到服務器(firebase存儲) 我相信畢加索只顯示圖像是不是?如果畢加索可以調整(或壓縮)源自身,這將會有所幫助。 – Jarvis