I want to get mime type of a bitmap object. Actually I have compressed a bitmap using
bitmap.compress (Bitmap.CompressFormat.PNG , 100, stream);
Now I want to cross check the format, outBounds and memory space size. But I don't wanna do a lengthy or a tedious task eg. to convert it to back to stream and then convert it again to BItmap using BitmapFactory with options.
Like Dmitry suggests, if what you have is a compressed image in a stream, then you do need to decode it using a BitmapFactory to tell what type it is. (Technically, you could also read the stream yourself and run your own ad hoc file format checks on it, but I assume you'd prefer to use existing tools rather than rolling your own.)
One optimization you can and should make is to set BitmapFactory.Options.inJustDecodeBounds to avoid needlessly decoding the entire image if you just want to know what type it is. After decoding, the outMimeType property should give you the type of the image.
As for the literal question in your title, it doesn't make sense. A Bitmap has no MIME type — it's just a container for an array of pixels. You can compress the bitmap into a stream using various formats, like JPEG, PNG or WEBP, but that just gives you a compressed copy of the image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With