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

时间:2011-03-14 06:53:11

标签: android

我希望以字节为单位获取图像大小...

//此代码在画廊中切换我可以选择任何现有图像

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

//此代码片段从库中返回所选图像的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);}}}

感谢..

1 个答案:

答案 0 :(得分:1)

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