2
我正嘗試將圖像上載到服務器。但是,在執行上載之前,我會檢查圖像大小是否大於2MB。 從活動結果收到圖像後,我運行下面的代碼使用字節數組檢查圖像大小
Bitmap bitmap = MediaStore.Images.Media.GetBitmap(this.Activity.ContentResolver, uri);
//int imageSize = 79030;
//float size = (bitmap.RowBytes * bitmap.Height)/1024;
//float seasonDrop = size/10000;
//double actualsizeMb = Math.Round(seasonDrop, 1);
// Rotate the image if required. Samsung devices have an Exif property that usually rotates the image.
bitmap = rotateImageIfRequired(bitmap, this.Activity, uri);
int size = bitmap.ByteCount;
var bytesize = bitmap.RowBytes * bitmap.Height;
var buffer = Java.Nio.ByteBuffer.Allocate(bytesize);
bitmap.CopyPixelsToBuffer(buffer);
buffer.Rewind();
var bytes = new byte[bytesize];
float length = bytes.Length/(1024 * 1024);
我試着上傳1.96MB圖像。但是,當我在長度上放置一個斷點時,我得到的值是10MB。這應該不可能像這樣增加圖像尺寸。
'上傳1.96MB image'到底是什麼1.96 MB? – greenapps
'嘗試將圖像上傳到服務器。您嘗試上傳位圖的所有像素。你沒有告訴位圖來自哪裏。但是,如果你想上傳文件,然後直接上傳這些文件,不要開始搞亂BitmapFactory或Bitmaps。 – greenapps
服務器想要接收什麼?無法解碼的文件或字節流?或者可以嗎? – greenapps