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

时间:2017-06-08 09:15:30

标签: android image bitmap imageview

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

我生成ImageViewXML

<ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="match_parent"/>  

并获取将所选图像从文件夹放入该ImageView

的功能
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(位图)获取图像细节(例如名称)但它返回时: android.graphics.Bitmap @ 5280fcb4

如何获取图像细节?

2 个答案:

答案 0 :(得分:0)

试试这个

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; 

答案 1 :(得分:0)

String path = (String) imageView .getTag();

你可以通过这个getTag()得到图像的路径,从而得到图像的名称