采用了Android摄像头的意图,得到的URI,然后使用URI [英] Using android camera intent, getting uri, and then using uri

查看:140
本文介绍了采用了Android摄像头的意图,得到的URI,然后使用URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下因素code:

I have a folowing code:

public void take_picture(View view)
{


 Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
 startActivityForResult(cameraIntent, CAMERA_REQUEST); 
}


protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    ImageView slikaa = (ImageView)this.findViewById(R.id.slikaa);
    if ((requestCode == CAMERA_REQUEST)&& (resultCode == Activity.RESULT_OK)) {  

Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        slikaa.setImageBitmap(photo);


} 

现在我的问题是如何获取图像路径(将其保存到我的数据库),然后再次,用它在图片显示(我不知道怎么弄的路径字符串,然后再利用它)

Now my question is how to get that image path(for saving it to my database), and then again, use it to show in a picture(I don't know how to get String paths, and then re-use it)

推荐答案

有关获取图像路径在onActivityResult则需要通过发送图片的路径,意图以启动相机:

For getting Image Path in onActivityResult you will need to Start camera by send Image Path with Intent as:

       Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  

        //ContentValues values = new ContentValues();  
        ContentValues values = new ContentValues(3);  
        values.put(MediaStore.Images.Media.DISPLAY_NAME, "testing");  
        values.put(MediaStore.Images.Media.DESCRIPTION, "this is description");  
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");  
        imageFilePath = MainActivity.this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageFilePath); 

        startActivityForResult(intent, CAMERA_REQUEST); 

和onActivityResult

and on onActivityResult

            protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
           ImageView slikaa = (ImageView)this.findViewById(R.id.slikaa);
            if ((requestCode == CAMERA_REQUEST)&& (resultCode == Activity.RESULT_OK)) {  
           //get image from path

            Bitmap photo = (Bitmap) data.getExtras().get("data"); 
            photo = BitmapFactory.decodeStream(this.getContentResolver()  
                .openInputStream(imageFilePath), null, op);  
            slikaa.setImageBitmap(pic);  

            //slikaa.setImageBitmap(photo);
          } 

这篇关于采用了Android摄像头的意图,得到的URI,然后使用URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆