【问题标题】:How to create camera button that stores images to gallery?如何创建将图像存储到图库的相机按钮?
【发布时间】:2013-04-27 19:21:08
【问题描述】:

如何正确获取按钮意图拍照并将该图像存储在手机图库中?到目前为止,我有一个按钮,它是一个案例结构,上面写着:

else if (v.getId() == R.id.button5)//相机

        {

                Intent c  = new Intent( MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(c,1);





        }

我的 onActivityResult 应该是什么样子,因为我只是将该图像存储到图库中?

我是否必须使用一些东西作为 bundle extras = data.getExtras();?

【问题讨论】:

    标签: android button android-intent camera gallery


    【解决方案1】:

    This 答案可能是您的问题解决方案。但是 data.getExtras() 在某些情况下返回 null ,不幸的是我还没有检测到所有这些情况。例如 data.getExtras() 在 android 2.3 HTC Evo 3D 上运行良好,但在 android 2.3 Samsung Galaxy SII 上,它返回 null。希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      首先,你必须像下面这样调用你的 startActivityForResult() 方法:

      Uri imageFileUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, new  ContentValues());
      Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
      startActivityForResult(i, CAMERA_RESULT);
      

      在 startActivityForResult() 方法的实现中,你必须编写以下内容:

      // Save the name and description of an image in a ContentValues map.
      ContentValues contentValues = new ContentValues(3);
      contentValues.put(Media.DISPLAY_NAME, "This is a test title");
      contentValues.put(Media.DESCRIPTION, "This is a test description");
      contentValues.put(Media.MIME_TYPE, "image/jpeg");
      // Add a new record without the bitmap, but with some values set.
      // insert() returns the URI of the new record.
      Uri imageFileUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,contentValues);
      

      【讨论】:

        猜你喜欢
        • 2019-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-08
        • 1970-01-01
        相关资源
        最近更新 更多