0

我想询问将路径图像发送到其他活动并显示到 imageview

浏览照片.java

private static int PICK_FROM_FILE = 1;
private static int INTENT_IMAGE = 2;
private ImageButton buttonLoadImage;
private ImageButton reloadPhoto;
private ImageButton imagedone;
private ImageView mImageView;
private Uri mImageCaptureUri;
TextView textImagePath;

Uri imageUri = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.push_left_in, R.anim.hold);
    setContentView(R.layout.browse);

    buttonLoadImage = (ImageButton) findViewById(R.id.btnLoadImage);
    imagedone = (ImageButton) findViewById(R.id.btnPhotoOk);
    reloadPhoto = (ImageButton) findViewById(R.id.btnReLoad);
    mImageView = (ImageView) findViewById(R.id.iv_pic);
    textImagePath = (TextView) findViewById(R.id.imagepath);

    buttonLoadImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);

            startActivityForResult(
                    Intent.createChooser(intent, "Complete action using"),
                    PICK_FROM_FILE);

            buttonLoadImage.setVisibility(View.INVISIBLE);
            imagedone.setVisibility(View.VISIBLE);
            reloadPhoto.setVisibility(View.VISIBLE);
        }
    });

    findViewById(R.id.btnPhotoOk).setOnClickListener(this);
    findViewById(R.id.btnReLoad).setOnClickListener(this);

}

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btnPhotoOk:
        moveToEditPhotoDrawerActivity();

        break;
    case R.id.btnReLoad:
        backToBrowsePhotoDrawerActivity();
        break;
    default:
        break;
    }
}

private void moveToEditPhotoDrawerActivity() {
    Intent intent = new Intent();
    startActivityForResult(intent, INTENT_IMAGE);
}

private void backToBrowsePhotoDrawerActivity() {
    Intent intent = new Intent(this, BrowsePhoto.class);
    startActivity(intent);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode != RESULT_OK)
        return;

    Bitmap bitmap = null;
    String path = "";

    if (requestCode == PICK_FROM_FILE) {
        mImageCaptureUri = data.getData();

        path = getRealPathFromURI(mImageCaptureUri);

        if (path == null)
            path = mImageCaptureUri.getPath();

        if (path != null)
            bitmap = BitmapFactory.decodeFile(path);
    } else {
        path = mImageCaptureUri.getPath();
        bitmap = BitmapFactory.decodeFile(path);


    }

    mImageView.setImageBitmap(bitmap);

    textImagePath.setText(path.toString());

    if(requestCode == INTENT_IMAGE){
        Intent intent = new Intent(this, EditImage.class);
        intent.putExtra("intent_image", path);
        startActivity(intent);
    }

}

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);

    if (cursor == null)
        return null;

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

    cursor.moveToFirst();

    return cursor.getString(column_index);
}

编辑图像.java

    String picturePath = getIntent().getStringExtra("intent_image");
    ImageView imageView = (ImageView) findViewById(R.id.iv_pic);
    imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

我从 sd 卡加载图像后的屏幕截图

![我从 sd 卡加载图像后的屏幕截图][1]

如果我单击正确的按钮,则意图编辑图像

代码有什么问题?如果你帮助我,你节省了我的时间:(

4

2 回答 2

0

根据您的描述,您要将图像路径从一个活动传递到另一个活动,您必须首先检查您获得的图像路径是否正确。然后在另一个活动中,检查路径是否正确传输。

于 2013-07-24T03:13:56.593 回答
0

从您的onActivityResult

if(requestCode == INTENT_IMAGE){
    Intent intent = new Intent(this, EditImage.class);
    intent.putExtra("intent_image", path);
    startActivity(intent);
}

moveToEditPhotoDrawerActivity并改变

    private void moveToEditPhotoDrawerActivity() {
    Intent intent = new Intent(this, EditImage.class);
    intent.putExtra("intent_image", path);
    startActivity(intent);
}
于 2013-07-25T03:50:24.587 回答