gpt4 book ai didi

android - 以字节为单位获取图像大小

转载 作者:行者123 更新时间:2023-11-29 02:14:17 25 4
gpt4 key购买 nike

我想获取以字节为单位的图像大小我应该怎么做..

//此代码将我切换到图库中,我们可以在其中选择任何现有图像

Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
i.setType("image/*");
startActivityForResult(i, 2);

//此代码 fragment 返回图库中所选图像的 uri,但我也想从此处获取图像//以字节为单位

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == 2) {// 2 for selectimage
// Get the data of the image selected? and upload to server

if (resultCode == Activity.RESULT_OK) {
ImageURI = data.getData();
Log.d("IMAGE PATH",""+ImageURI);}}}

谢谢..

最佳答案

ContentResolver resolver = context.getContentResolver();
InputStream is = resolver.openInputStream(ImageURI);
BitmapFactory.Options bounds = new BitmapFactory.Options();
BitmapFactory.decodeStream(is,null,bounds);
int width = bounds.outWidth;
int height = bounds.outHeight;
int size = width * height * bytes_per_pixel

关于android - 以字节为单位获取图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5295607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com