Android Emulator显示SD卡图像

时间:2013-12-24 06:28:36

标签: android android-imageview android-image

你好!!我正在尝试编写一个非常简单的 android程序。当我从图库中按下所选图像上的share button时,会弹出一个菜单,告诉我在我的应用程序和消息应用程序之间进行选择以打开图像。当我选择我的应用程序时,我希望它在image view中查看图像。对于我已经完成的部分是按下分享按钮的隐含意图,它会弹出一个菜单供我选择我想要使用的应用程序。第二部分是棘手的部分,因为图像保存在手机的SD卡上如何访问该特定图像,如何在image view中查看?我正在使用Android Emulator

1 个答案:

答案 0 :(得分:0)

首先创建一个具有sdcard then how to save image in emulator

的模拟器

从sdcard中挑选图片你可以关注this tutorial

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

    switch(requestCode) { 
    case REQ_CODE_PICK_IMAGE:
        if(resultCode == RESULT_OK){  
            Uri selectedImage = imageReturnedIntent.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

            Cursor cursor = getContentResolver().query(
                               selectedImage, filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            cursor.close();


            Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
            yourImageView.setImageBitmap(yourSelectedImage);
        }
    }
}

在ur imageview use this

中显示该图片
ImageView img=(ImageView) findViewById(R.id.ur_imageview);
Bitmap bmp = BitmapFactory.decodeFile(filePath);
img.setImageBitmap(bmp);
相关问题