Android 获取位图图像详细信息(例如宽度和高度)
如何获取在图像视图中选择的图像细节(名称、宽度、高度、大小等) 我生成ImageViewXMLAndroid 获取位图图像详细信息(例如宽度和高度),android,image,bitmap,imageview,Android,Image,Bitmap,Imageview,如何获取在图像视图中选择的图像细节(名称、宽度、高度、大小等) 我生成ImageViewXML <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="match_parent"/> Uri uri = data.getData(); try { Bitmap bitmap = MediaStore
<ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="match_parent"/>
Uri uri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
//Log.d(TAG, String.valueOf(bitmap));
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
当我想通过使用String.valueOf(位图)获取图像详细信息(例如名称)时,它可以正常工作,没有bug,但返回的结果是:android.graphics。Bitmap@5280fcb4
如何获取图像细节?试试这个
Bitmap bitmap = ((BitmapDrawable)imageView.getBackground()).getBitmap();
int width = bitmap .getWidth();
int height = bitmap .getHeight();
图像大小
Bitmap bitmap = ((BitmapDrawable)imageView.getBackground()).getBitmap();
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytestream );
byte[] imageByte = bytestream .toByteArray();
long lengthbmp = imageByte .length;
您可以通过这个getTag()从中获取图像的路径,该路径应该可以获取图像的名称图像名称如何?请尝试这个
String filename=uri.getLastPathSegment()代码>不起作用,它返回整数值,在我的例子中是30it返回null,现在,我们需要在xml文件中手动标记它:android:Tag=“any name”?
String path = (String) imageView .getTag();