how to get image size in bytes from imageview (android)

541 views Asked by At

i am working on an wallpaper app in which i am receiving images from Picasa Web Album in GridView and Full Screen ImageView.

i want to save ImageView loaded image using image bytes size, to prevent duplicate save, but i don't knowhow to get image bytes size from ImageView.`

this is my code:

int intHeight = fullImageView.getHeight();
            int intWidth = fullImageView.getWidth();                    

            String dirname2 = "/Amazing Wallpapers HD/";

            File myDir2 = new File(Environment.getExternalStorageDirectory()
                    .getPath() + dirname2);

            myDir2.mkdirs();

            String fname2 = "image" + intHeight+ intWidth +".jpeg";
            File file2 = new File(myDir2, fname2);

            if (file2.exists())
                file2.delete();
            try {
                FileOutputStream out = new FileOutputStream(file2);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
                out.flush();
                out.close();

            } catch (Exception e) {
                Toast.makeText(_context, "failed", Toast.LENGTH_SHORT).show();
            }

Note: i am asking about size of image in bytes or kilobytes.

2

There are 2 answers

0
cgew85 On

You can use BitmapFactory.Options for that. It'll only extract the meta data of the image not the image as a whole.You should be able to get enough data from there to ensure you wont have a duplicate. For further reading: Android Developers

0
Muhammed Refaat On

If you are working with Picasa you can simply get photo description which will gives you a lot of unique features in order to use it in your work:

photo.getDescription().getPlainText()

you will find more details here.