android 如何在 ActivityResult() 上获取图像的实际大小
How to get the actual size of image on ActivityResult() in android
下面是我的代码。单击 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;
}
}
}
-您需要获取完整的图像路径,而不仅仅是来自 intent extra 的数据,然后从该路径获取您的文件,只有这样您才能获得图片的真实大小。
- 你可以使用一些选择器库或者你可以检查这个 link
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));
下面是我的代码。单击 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;
}
}
}
-您需要获取完整的图像路径,而不仅仅是来自 intent extra 的数据,然后从该路径获取您的文件,只有这样您才能获得图片的真实大小。 - 你可以使用一些选择器库或者你可以检查这个 link
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));