[英]Check if picture in imageview was captured from camera or gallery
I am able to capture an image from gallery or camera and put it in imageview with following code: 我能够从图库或照相机中捕获图像,并使用以下代码将其放入imageview中:
1. Capture image from gallery or camera: 1.从图库或照相机中捕获图像:
private void captureImageInitialization() {
final String[] items = new String[] { "Take from camera",
"Select from gallery" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.select_dialog_item, items);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select Image");
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) { // pick from
// camera
if (item == 0) {
Intent intent = new Intent(
"android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, PICK_FROM_CAMERA);
} else {
// pick from file
/**
* To select an image from existing files, use
* Intent.createChooser to open image chooser. Android will
* automatically display a list of supported applications,
* such as image gallery or file manager.
*/
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Complete action using"), PICK_FROM_FILE);
}
}
});
dialog = builder.create();
}
2. Show in imageview: 2.在imageview中显示:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK)
return;
switch (requestCode) {
case PICK_FROM_CAMERA:
mImageCaptureUri = data.getData();
imagepath = getPath(mImageCaptureUri);
bitmap = BitmapFactory.decodeFile(imagepath);
mImageView.setImageBitmap(bitmap);
// Log.d("camera ---- > ", "" + data.getExtras().get("data"));
new ProcessUploadAvatar2().execute();
break;
case PICK_FROM_FILE:
/**
* After selecting image from files, save the selected path
*/
mImageCaptureUri = data.getData();
imagepath = getPath(mImageCaptureUri);
bitmap2 = BitmapFactory.decodeFile(imagepath);
mImageView.setImageBitmap(bitmap2);
break;
}
}
Now my question is how to check if the image in the imageview has been taken by camera or gallery beyond the onActivityResult() method? 现在我的问题是如何检查图像视图中的图像是否已由onActivityResult()方法之外的相机或图库拍摄? I try to implement something like this:
我尝试实现这样的事情:
public void NetAsync() {
if (mImageView.getDrawable() != null) {
if (mImageView = bitmap) {
new NetCheck().execute();
} else if (mImageView = bitmap2) {
new ProcessUploadAvatar2().execute();
}
}
}
您可以通过在onActivityResult()中对请求代码进行一次检查来轻松获得此代码...我的意思是您在调用相机/图库意图时发送的那些请求代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.