【问题标题】:Android Emulator Display Image from SD CardAndroid 模拟器从 SD 卡显示图像
【发布时间】:2013-12-24 06:28:35
【问题描述】:

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

【问题讨论】:

  • 请出示您的代码。
  • 模拟器中没有SD卡。
  • 我认为你的模拟器的sd卡中没有图像

标签: android android-imageview android-image


【解决方案1】:

首先创建一个带有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);
        }
    }
}

用于在您的图像视图中显示该图像use this

ImageView img=(ImageView) findViewById(R.id.ur_imageview);
Bitmap bmp = BitmapFactory.decodeFile(filePath);
img.setImageBitmap(bmp);

【讨论】:

    猜你喜欢
    • 2011-10-07
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    相关资源
    最近更新 更多