由网友(vulgar 庸俗)分享简介:我一直在寻找的简单的例子来拍摄照片,并使用URI保存和retrive照片进行图像处理,我试过很多例如code,但他们都不顺利。i've been searching the simple example to take a photo, and save it using URI and retrive the p...
我一直在寻找的简单的例子来拍摄照片,并使用URI保存和retrive照片进行图像处理, 我试过很多例如code,但他们都不顺利。
i've been searching the simple example to take a photo, and save it using URI and retrive the photo for image processing , i've tried lot of example code, but none of them went smoothly.
有没有人有这个例子code?
is there anyone have the example code?
太感谢你了。
推荐答案
像这样定义一个变量
protected static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 0;
使用的code从Android的呼叫相机。
Use the code for calling camera from android.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"fname_" +
String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
和在类中调用这个覆盖onActivityResult功能,并在下面输入code。
and in the class calling this override the onActivityResult function and enter the code below.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
//use imageUri here to access the image
Bundle extras = data.getExtras();
Log.e("URI",imageUri.toString());
Bitmap bmp = (Bitmap) extras.get("data");
// here you will get the image as bitmap
}
else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT);
}
}
}
相关推荐
最新文章