Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取位图图像详细信息(例如宽度和高度)_Android_Image_Bitmap_Imageview - Fatal编程技术网

Android 获取位图图像详细信息(例如宽度和高度)

Android 获取位图图像详细信息(例如宽度和高度),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

如何获取在图像视图中选择的图像细节(名称、宽度、高度、大小等)

我生成ImageViewXML

<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();