0

我正在从 IO 文件管理器(已安装)中检索图像。无论如何,当我尝试检索图像时,我不确定它去了哪里?或者如何将其保存为位图?

下面的代码:

public void onClick(View v)
{
    if(v.getId() == R.id.facebook_icon || v.getId() == R.id.facebook_text)
    {
        //Facebook
    }

    if(v.getId() == R.id.camera_icon || v.getId() == R.id.camera_text)
    {
        //Camera
    }

    if(v.getId() == R.id.folder_icon || v.getId() == R.id.folder_text)
    {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent,"Select Picture"), MODE_WORLD_READABLE);
    }
}

protected void onActivityForResult()
{
    //Where is the image? How to get?
    System.out.println("Image gotton");
}
4

1 回答 1

1

首先,您没有覆盖 onActivityResult。注意方法签名: http: //developer.android.com/reference/android/app/Activity.html#onActivityResult (int , int, android.content.Intent)

您应该使用@Override 注释,这样您就知道什么时候出了问题。

尝试类似:

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK)
    {
        Uri imageUri = data.getData();
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
    }
}
于 2012-06-28T21:28:55.140 回答