获取ImageView图像位置

时间:2014-03-25 04:32:15

标签: android image

我正在使用ImageView来显示存储在SD卡中的图像。像这样 -

    ImageView grp_icon=(ImageView)gridView.findViewById(R.id.grid_item_image);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            String path="/sdcard/Letsmeet/letsmeet_media/group_images/"+gridImage[position];
            Bitmap bitmap = BitmapFactory.decodeFile(path, options);
            grp_icon.setImageBitmap(bitmap);

我试图通过在Intent中发送位置来获取图像位置以在另一个活动中显示相同的图像。但它给出了不同的位置为什么?

我获得ImageView图像位置的代码是

String groupName=((TextView) v.findViewById(R.id.grid_item_label)).getText().toString();
                ImageView grp_image=(ImageView)v.findViewById(R.id.grid_item_image);
                Bitmap b=((BitmapDrawable)grp_image.getDrawable()).getBitmap();
                Uri image=getImageUri(getActivity().getApplicationContext(), b);
                String path=image.toString();
                Intent toMangeGroup=new Intent(getActivity(),ManageGroup.class);
                Bundle bundle=new Bundle();
                bundle.putString("grp_name", groupName);
                bundle.putString("grp_image", path);
                toMangeGroup.putExtras(bundle);
                startActivity(toMangeGroup);

此处我将路径设为"content://media/external/images/media/42424",但图片的实际路径为"/sdcard/Letsmeet/letsmeet_media/group_images/1395247992445"

4 个答案:

答案 0 :(得分:0)

System.out.println("this is path where stored.."
                + Environment.getExternalStorageDirectory()
                        .getAbsolutePath());

答案 1 :(得分:0)

尝试使用此方法获取SD卡上的文件路径:

String filePath = Environment.getExternalStorageDirectory().toString() + File.separator + "Letsmeet/letsmeet_media/group_images/" + gridImage[position];

答案 2 :(得分:0)

使用此代码:可以帮助您..

Bitmap mybit=BitmapFactory.decodeFile(file1.getAbsolutePath());
image.setImageBitmap(mybit);

用于以文件格式存储图像并从该路径获取图像。

答案 3 :(得分:0)

看看这个Get filename and path from uri from mediastore。 Nikolay Nikiforchuk提供的答案是要走的路。这不仅适用于mediafile,而且适用于SDCard

上存储的所有文件

只需替换此行

int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

这一个

int column_index = cursor.getColumnIndexOrThrow("_data");

这样可以正常工作。