Yes, it is possible to obtain the width and height of an image file from a URI on an Android device. One way to do this is by using the BitmapFactory class in Android. Here is an example:
val uri = // the URI of the image file
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeFileDescriptor(context.contentResolver.openFileDescriptor(uri, "r")?.fileDescriptor, null, options)
val width = options.outWidth
val height = options.outHeight
In this example, we first create a BitmapFactory.Options object and set the inJustDecodeBounds property to true. Then we use the decodeFileDescriptor method of the BitmapFactory class to decode the file and obtain the image dimensions without actually loading the full bitmap into memory. Finally, we can access the width and height values from the BitmapFactory.Options object.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-10 01:09:50 +0000
Seen: 13 times
Last updated: May 10 '23
Why isn't the CSS background image being displayed?
How can I show an image in my Qt project?
How can I execute a React Native application on my Android device?
What is the process to activate the screen time off feature in Android using AOSP customization?
What triggers the sending of a TCP/IP reset (RST) flag?
Can files saved on a distant device be modified through Apache Netbeans 17?
One way to display the display of a tangible device within Android Studio is by using what method?