android - 使用android camera intent,获取uri,然后使用uri

标签 android camera gallery uri

我有以下代码:

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);


} 

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

最佳答案

要在 onActivityResult 中获取图像路径,您需要通过发送带有 Intent 的图像路径来启动相机:

       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

            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 - 使用android camera intent,获取uri,然后使用uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12122491/

相关文章:

java - 在 Realm 中使用预填充的数据库

android - Fragment 中处理信息的通知 Activity

android - 对特定路径使用 Intent.ACTION_PICK

jquery - 使用其他链接调用 fancybox gallery

android - ImageView 上的缩放动画在 >4.0 操作系统设备中不起作用

java.lang.IllegalStateException : Default FirebaseApp is not initialized in this process com. example.bottomnav

android - AVD 加载失败

ios - SceneKit:在没有相机跳跃或将 anchor 移动到中心的情况下围绕任意点运行?

android - 如何在 Android N 多窗口模式下确定正确的设备方向?

ios - 自动释放中的 Worklight 6.2 和相机 iOS 错误