how to check image size less then 100kb android

前端 未结 4 842
情深已故
情深已故 2021-01-12 07:43

I am trying to get image from gallery and setting up it on ImageView , Hear is okay well i get and set image on ImageView, but now i want to check

4条回答
  •  心在旅途
    2021-01-12 07:53

    Just input URI from the intent and get the size of any file

    uri = data.getData();
            Cursor returnCursor = getContentResolver().query(uri, null, null, null, null);
            int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
            int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
            returnCursor.moveToFirst();
            Log.e("TAG", "Name:" + returnCursor.getString(nameIndex));
            Log.e("TAG","Size: "+Long.toString(returnCursor.getLong(sizeIndex)));
    

    It will give size in bytes, So 100kb will be 100000bytes. I think this will help you.

提交回复
热议问题