Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the size of an image in Android?

I'm able to get the height and width of an image. But is there a method to retrieve the size (in bytes or kb or mb) for an image stored in the phone?

like image 975
Ahmed Avatar asked Feb 16 '12 18:02

Ahmed


People also ask

How can you tell the size of a photo on android?

On android go to photos, select your photo and click the ... in the top right. Scroll to bottom of page to find image size.

How do I find out image size?

Find the size of an imageRight-click on the image (or, on a Mac, control-click). Choose Properties or Get info. Click the General or More info tab. Use the Image section to see the image dimensions in pixels, or the File section to see the image file size.

How do I find file size on android?

file. length() returns the length of the file in bytes, as described in the Java 7 Documentation: Returns the length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist. Some operating systems may return 0L for pathnames denoting system-dependent entities such as devices or pipes.


1 Answers

Thank you for your answers. This is how I finally resolved it:

 Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), 
            R.drawable.ic_launcher);


     Bitmap bitmap = bitmapOrg;
     ByteArrayOutputStream stream = new ByteArrayOutputStream();   
     bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);   
     byte[] imageInByte = stream.toByteArray(); 
     long lengthbmp = imageInByte.length; 

Appreciate your time and answers :)

like image 100
Ahmed Avatar answered Oct 08 '22 08:10

Ahmed