android question
android question

Reputation: 9

how to get image type from imageview (android)

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

i want to save ImageView loaded image using its real image type, but i don't know how to get image type from ImageView.

example: if loaded image is JPEG or PNG then how do i get image type.

this is my code that i am using to save image as JPEG:

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

            String dirname2 = "/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();
            }

Upvotes: 0

Views: 1113

Answers (1)

JstnPwll
JstnPwll

Reputation: 8685

Perhaps you should keep track of this yourself. In the code you use to set the ImageView's drawable, you could apply a tag to the view to store that data:

String[] parts = fileName.split(".");
String extension = parts[parts.length-1];
imageView.setTag(extension);

And retrieve it from the view later:

String ext = (String) fullImageView.getTag();

Upvotes: 2

Related Questions