本文介绍了Android的 - 如何从负载图像从SD卡发送图像到其他活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想请教一下发送路径图像等活动,并展示给ImageView的
i want to ask about send path image to other activity and show to imageview
BrowsePhoto.java
BrowsePhoto.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);
}
EditImage.java
EditImage.java
String picturePath = getIntent().getStringExtra("intent_image");
ImageView imageView = (ImageView) findViewById(R.id.iv_pic);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
Screenshoot后,我加载图像从SD卡
Screenshoot after i load image from sd card
![Screenshoot后,我加载从SD卡图像] [1]
![Screenshoot after i load image from sd card][1]
和如果我点击按钮正确的,那么意图editimage
and if i click button correct, then intent to editimage
什么是从code错了吗?
如果你能帮我,你救了我的时间:(
what is wrong from the code?if you help me, you saved my time :(
推荐答案
从删除这些行的的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);
}
这篇关于Android的 - 如何从负载图像从SD卡发送图像到其他活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!