Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Image Format of the images from Gallery

I want to know the Image format (i.e. JPFG/PNG etc) of the images which I am getting from the gallery.

My need is to pic images from the gallery of the device and send it to server in Base64 format but the server wants to know image format.

Any help is appreciated.

like image 697
Vineet Shukla Avatar asked Feb 23 '12 13:02

Vineet Shukla


People also ask

How do I know the format of an image?

If you are having trouble and want to check if you photo is a JPEG, look at the writing under the photo in its file name. If it ends . jpg or . jpeg- then the file is a JPEG and will upload.

How do I change a picture to JPG?

Go to File > Save as and open the Save as type drop-down menu. You can then select JPEG and PNG, as well as TIFF, GIF, HEIC, and multiple bitmap formats. Save the file to your computer and it will convert.

How do I change the format of a picture on my phone?

The current file format used by your Android device is displayed under the Screenshot format entry. To change it, tap on it. To change the screenshot format on your Android to JPG or PNG, tap on the file type you want to use from the dropdown menu.

What format are pictures on android?

Android apps typically use images that are in one or more of the following file formats: AVIF, PNG, JPG, and WebP.


1 Answers

It is possible to get MIME type with path alone.

 public static String getMimeType(String imageUrl) {
        String extension = MimeTypeMap.getFileExtensionFromUrl(imageUrl);
        String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
                extension);
        // Do Manual manipulation if needed
        if ("image/x-ms-bmp".equals(mimeType)) {
            mimeType = "image/bmp";
        }
        return mimeType;
    }
like image 164
Mahendran Avatar answered Oct 20 '22 18:10

Mahendran