【问题标题】:capture a new image using existing image with camera app in android使用现有图像和 android 中的相机应用程序捕获新图像
【发布时间】:2012-07-23 10:36:17
【问题描述】:

我打算在 Android 中制作一个应用程序,我们可以在其中从图库中选择一张图片,然后使用该图片和 Android 相机 应用程序我们必须捕获一个新图像并保存到 SD 卡

从图库中选择图像并打开相机应用程序可以通过Intent完成,但是如何将这两者结合起来。

我还在 Android 中搜索了screen shot 选项,但它说出于安全考虑,设备必须为此植根

非常感谢任何帮助

【问题讨论】:

  • 只有我一个不明白这个问题吗...?
  • 抱歉我的英语不好,实际上需要将我从图库中选择的图像导出到 android 中的相机应用程序。然后我必须使用相机应用程序捕获一张新图像。跨度>
  • 你是什么意思“有了那张照片,我必须捕捉一个新图像”??替换旧图片,还是什么?
  • 图库中的图像将存在于相机表面,因此当我使用相机拍摄照片时,新拍摄的照片将包含图库中的旧照片。就像图像编辑一样

标签: android screenshot android-camera


【解决方案1】:

私有静态最终 int GET_IMAGE = 2;

cameraButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog alertDialog=new AlertDialog.Builder(FotografiActivity.this).setTitle("Byggekort")
            .setMessage(R.string.camera_open_msg).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    takePhoto();
                }
            }).create();
            alertDialog.show();
        }
    });

private void takePhoto() {
    final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(getTempFile(this)));
    startActivityForResult(intent, TAKE_PHOTO_CODE);
}




public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == GET_IMAGE) {
                targetUri = data.getData();
                fotografiImageView.setImageURI(targetUri);
                selectedImagePath =getPath(targetUri);
                Bitmap captureBmp;
                try {
                    captureBmp = Media.getBitmap(getContentResolver(),
                            targetUri);
                    applicationActivity.dataArray.put(PHOTO_URI, captureBmp);
                    applicationActivity.dataUri.put(URI1, selectedImagePath);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

【讨论】:

  • takePhoto 是在名为 cameraButton 的按钮的单击事件上调用的函数.....在该函数中,我调用了用于打开设备图库的活动...并通过使用启动了活动...StartActivityforResult ...这是内置在android中...执行onActivityResult ....
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-09
  • 1970-01-01
  • 1970-01-01
  • 2012-01-11
相关资源
最近更新 更多