image size in kb for upload

Asked

Viewed 221 times

1

I am making an application for android, and have to work with download and upload photos... I am already resizing photos larger than 1000x1000px to this same size... and using the method

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

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

my problem is that some images pass 3mb and using the compress as above, they stay close to 500kb, and would have to pass once more in the compress to get smaller

but at the same time there are 50kb images that when passing in compress stay with 8kb or would not need compress...

then I need a method that returns the image size in kb or Mb whatever... then I could deal with this problem of mine...

thank you in advance.

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!");
        }

    }
}

Source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.