下面是我的代码。点击imageview相机将打开,我们将捕获图像。在下面的onActivityResult中,图像大小与缩略图大小相同。我想要实际的图像尺寸。怎么办?
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
if (CAMERA_REQUEST == 1) {
ivBeforeLoading.setImageBitmap(photo);
ivBeforeLoading.setBackgroundResource(0);
imgBefLoad = photo;
}
}
}
--您需要获取完整的图像路径,不仅要从意图中获取额外的数据,还要从该路径中获取文件,只有这样,您才能获取图片的真实大小。-您可以使用某些选择器库,也可以只检查此链接
Dialog to pick image from gallery or from camera
您会找到想要的东西
尝试一下(how do I get file size of temp file in android?)
File file = new File(selectedPath);
int file_size = Integer.parseInt(String.valueOf(file.length()/1024));