在我的应用中,用户要么从他们的图片库中挑选一张图片,要么用他们的相机拍摄一张图片。
当您捕获它时,它会添加到用户的图库中。
我发现这些图像,除了是相同的图像之外,尺寸也有很大的变化。
捕获:33kb
代码:
if (requestCode == TAKEIMAGE) {
System.out.println("TAKE IMAGE");
int photoLength = 0;
Bitmap photo = (Bitmap) data.getExtras().get("data");
photoLength = GetBitmapLength(photo);
SetSubmissionImage(photo, photoLength);
}
取自画廊:1600kb
代码:
else if (requestCode == CHOOSEIMAGE) {
System.out.println("CHOOSE IMAGE");
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
try {
FileInputStream fileis=new FileInputStream(selectedImagePath);
BufferedInputStream bufferedstream=new BufferedInputStream(fileis);
byte[] bMapArray= new byte[bufferedstream.available()];
bufferedstream.read(bMapArray);
int photoLength = 0;
Bitmap photo = BitmapFactory.decodeByteArray(bMapArray, 0, bMapArray.length);
bMapArray = null;
fileis.close();
bufferedstream.close();
//rotate to be portrait properly
try {
ExifInterface exif = new ExifInterface(selectedImagePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Log.e("EXIF", "Exif: " + orientation);
Matrix matrix = new Matrix();
if (orientation == 6) {
matrix.postRotate(90);
}
else if (orientation == 3) {
matrix.postRotate(180);
}
else if (orientation == 8) {
matrix.postRotate(270);
}
photo = Bitmap.createBitmap(photo, 0, 0, photo.getWidth(), photo.getHeight(), matrix, true); // rotating bitmap
}
catch (Exception e) {
}
//photo = GetCompressedBitmap(photo);
photoLength = GetBitmapLength(photo);
SetSubmissionImage(photo, photoLength);
}