size of images in kb for upload

1

I'm making an application for android, and I have to work with downloading and uploading photos ... I'm already resizing photos larger than 1000x1000px for this same size ... and using the method

yourSelectedImage.compress(Bitmap.CompressFormat.JPEG, 10, out);

To decrease the size of the image in KB for easy upload and download ...

My problem is that some images go from 3mb and using the compress as above, they are close to 500kb, and would have to pass the compress once more to get smaller

But at the same time there are images of 50kb that when passing in the compression are 8kb or you would not need the compression ...

So I need a method that returns the size of the image in kb or mb so much ... then I could handle this problem of mine ...

Thank you in advance.

    
asked by anonymous 16.02.2017 / 20:54

1 answer

0

Method length() :

import java.io.File;

public class FileSizeExample 
{   public static void main(String[] args)
    {   File file =new File("sua_imagem.ext");
        if(file.exists())
        {    double bytes = file.length();
             double kilobytes = (bytes / 1024);
             double megabytes = (kilobytes / 1024);
             System.out.println("bytes : " + bytes);
             System.out.println("kilobytes : " + kilobytes);
             System.out.println("megabytes : " + megabytes);
        }else
        {    System.out.println("Arquivo nem existe!");
        }

    }
}

Font

    
16.02.2017 / 21:12