Android: convert URI with x-photoshop to bitmap - android

How to convert Uri with MIME type "x-photoshop" to Bitmap?
I've googled "how to convert x-photoshop to bitmap Android".
I only found using MediaStore.Images.Media.getBitmap but that doesn't help.

Related

Re-create uri from decoded string

I get an Uri and I do:
String s = Uri.decode(uri.toString());
But when I encode the string again I haven't got the same result:
Uri uri = Uri.parse(Uri.encode(s));
Uri received without decoding (just called toString()):
content://com.android.externalstorage.documents/document/primary%3APictures%2FScreenshots%2FScreenshot_20190807-153556.png
Uri created via parse/encode method:
content%3A%2F%2Fcom.android.externalstorage.documents%2Fdocument%2Fprimary%3APictures%2FScreenshots%2FScreenshot_20190807-153556.png
Is there a way to re-parse correctly the Uri?
Is there a way to re-parse correctly the Uri?
No. Hold onto the original Uri. This is not significantly different than converting an image to monochrome, then wondering how to get the original color image back. The decode() and encode() methods are not designed to decode and encode Uri values, but rather specific pieces (e.g., query parameter values).

Android Upload Image using path or uri?

I'm having a trouble bringing the images from the gallery to my app.
The hard part is that, in some articles they use uri rather than path, but in others vice versa.
Plus, I'm not also sure... when I get Uri from the intent coming back, should I use cursor to get images data? (How to get Images from Cursor in android?) In some other references, they do it in the easy way, just with 'getPath()' method.
Do I need either of path or uri? or Only one of these?
I'm so confused now..
Always use Uri:
File file = new File(uri.getPath());
then
Bitmap bitmap= BitmapFactory.decodeFile(file.getAbsolutePath());
and when you have bitmap simply load it in to ImageView
imageView.setImageBitmap(bitmap);

Why MediaStore.Images.Media give me only BitMap while on the phone images are JPG

I'm "playing" with MediaStore.Images.Media and I saw that I can only retrieve BMP format (MediaStore.Images.Thumbnails.getThumbnail() - MediaStore.Images.Media.getThumbnail()), while the same images on my device actually are JPG.
I didn't find any clear explanation on the internet.
Can anybody help me understand better?
Thank you in advance.
getThumbnail() returns a Bitmap. This has nothing to do with the BMP file format. A Bitmap is a decoded image, regardless of the encoding of whatever the image came from (JPEG, PNG, WebP, GIF, BMP, etc.).

Scaling jpg image from Bitmap.compress android

I am converting, bitmap to jpeg using
val file = File(filePath)
val fos = FileOutputStream(file)
profileImageBitmap.compress(Bitmap.CompressFormat.JPEG,100,fos)
The jpeg looks okay. But its very tiny. I thought it was the jpeg lossy nature but when I tried to convert bitmap into png, it also came down to same size. Is there a way to increase the size of jpeg, compressed from bitmap?
You can use createScaledBitmap to scale up your bitmap before converting to jpeg, try passing true as the filter boolean to get better results. (You might want to decode the bitmap from the file first).
createScaledBitmap documentation

Read in JPG as RGB888 on Android

I'm trying to read in a .jpg using BitmapFactory. I want to get a RGB888 formatted bitmap, but I keep seeming to get RGB565. Is there anyway to change this?
BitmapFactory methods let you pass a BitmapFactory.Options instance. You can use BitmapFactory.Options to specifcy the inPreferredConfig, which defines the format of the Bitmap returned after decoding, just set it to Bitmap.Config.ARGB_8888.

Categories

Resources