Android 中如何获取照片的宽度和高度?

发布于 2024-12-29 11:57:19 字数 56 浏览 2 评论 0原文

我想根据照片的路径获取照片(图像)的宽度和高度。有没有办法在不将照片加载到内存的情况下做到这一点?

I want to get the width and height of a photo (Image) given the path of the photo. Is there a way to do that without loading the photo to the memory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

优雅的叶子 2025-01-05 11:57:19

是的,只需按以下方式使用 BitmapFactory 即可:

Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

BitmapFactory.decodeFile(path, options);

此后选项的 outHeight 和 outWidth 字段将包含位图大小。您可以根据您访问文件的方式使用decodeStream或其他函数,只是不要忘记提供BitmapFactory.Options。

Yes, just use BitmapFactory for this in following way:

Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

BitmapFactory.decodeFile(path, options);

After this fields outHeight and outWidth of options will contain bitmap size. You can use decodeStream or other function, based on way you access the file, just don't forget to provide BitmapFactory.Options.

绝情姑娘 2025-01-05 11:57:19

尝试此操作:

    BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;

Bitmap btemp = BitmapFactory.decodeFile(selectedImagePath,options);

在使用下面的代码获取高度和宽度后

     options.outHeight     for height
      options.outWidth    for width

try this

    BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;

Bitmap btemp = BitmapFactory.decodeFile(selectedImagePath,options);

after this use below code to get height and width:

     options.outHeight     for height
      options.outWidth    for width
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文