Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中通过多种活动使用相机拍摄的位图?_Android_Image_Android Intent_Android Activity_Bitmap - Fatal编程技术网

如何在android中通过多种活动使用相机拍摄的位图?

如何在android中通过多种活动使用相机拍摄的位图?,android,image,android-intent,android-activity,bitmap,Android,Image,Android Intent,Android Activity,Bitmap,我正在制作一个照片应用程序,在第一个活动中,用户拍摄一张照片(他可以在ImageView中看到照片),在第二个活动中,他选择与谁共享图像,在第三个活动中,他应该能够在与第一个不同的ImageView中再次看到图像,以添加一些数据。我知道如何通过意图将位图从一个活动移动到下一个活动,但是如果我想将其发送到用户路径的第三个活动,该如何操作?如果我开始活动(意图),它将跳过我的第二个活动,如果我不进行,第三个活动将向我显示一个空的图像视图。。有人能帮我告诉我如何在第一和第三个活动中自动加载(无需用户交

我正在制作一个照片应用程序,在第一个活动中,用户拍摄一张照片(他可以在ImageView中看到照片),在第二个活动中,他选择与谁共享图像,在第三个活动中,他应该能够在与第一个不同的ImageView中再次看到图像,以添加一些数据。我知道如何通过意图将位图从一个活动移动到下一个活动,但是如果我想将其发送到用户路径的第三个活动,该如何操作?如果我开始活动(意图),它将跳过我的第二个活动,如果我不进行,第三个活动将向我显示一个空的图像视图。。有人能帮我告诉我如何在第一和第三个活动中自动加载(无需用户交互)这张图片以及一些示例吗

我已经在阅读关于如何转换为Base64并再次加载的帖子,但是他们的例子是使用手机内存中已经存在的图像,在我的例子中是用户刚刚拍摄的照片,所以原则上我不知道图像文件的名称


非常感谢

实际上,在第二个活动中,您需要从第一个活动中获取意图并完成工作,然后创建新的意图并将图像放入其中,最后使用新的意图开始第三个活动

在第二项活动中:

Intent firstToSecodeIntent = getIntent();
// some codes
Intent secondToThirdIntent = new Intent(this, ThirdActivity.class);
Intent.putExtra("image", /*your Image object*/);
startActivity(secondToThirdIntent);
Intent secondToThirdIntent = getIntent();
// get your image and set it into your imageView
在第三项活动中:

Intent firstToSecodeIntent = getIntent();
// some codes
Intent secondToThirdIntent = new Intent(this, ThirdActivity.class);
Intent.putExtra("image", /*your Image object*/);
startActivity(secondToThirdIntent);
Intent secondToThirdIntent = getIntent();
// get your image and set it into your imageView

将此图像添加到您的Custome Catch文件夹中

例如,将文件夹置于外部或内部存储器中

然后将相机拍摄的图像保存在该文件夹中

public static void SaveImagecatch(Bitmap finalBitmap) throws IOException {

    File Folder = new File(Environment.getExternalStorageDirectory() + "/data/Catch");
    if (Folder.mkdir()) {
        nomediaFile = new File(Environment.getExternalStorageDirectory() + "/data/Catch/" + NOMEDIA);
        if (!nomediaFile.exists()) {
            nomediaFile.createNewFile();
        }
    }
    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + "/data/Catch");
    myDir.mkdirs();
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fname = "Image-" + n + ".jpg";
    File file = new File(myDir, fname);
    Catch_uri = Uri.parse("file://" + myDir + "/" + fname);
    if (file.exists()) file.delete();
    try {
        FileOutputStream out = new FileOutputStream(file);
        finalBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
        Log.e("yes", "yes");
    } catch (Exception e) {
        e.printStackTrace();
        Log.e("no", "no");
    }
}
然后。。从已保存图像的Uri路径获取图像

Uri imageUri = Catch_uri; 
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),imageUri);
Imageview my_img_view = (Imageview ) findViewById (R.id.my_img_view);
my_img_view.setImageBitmap(bitmap);

这是我的工作。。我希望这会对你有所帮助

这是真的吗?第一个活动启动第二个活动,然后第二个活动启动第三个活动。这是您的场景吗?是的,第一个场景为相机创建了一个意图,用户拍摄一张照片并返回到ImageView中,第二个场景是共享窗口活动,然后用户转到第三个场景,这是ImageView,用户必须再次看到他拍摄的照片。不知道如何将图像传递给第三个活动..在第三个活动中创建一个静态位图字段,从您当前的活动中可以填充第三个活动位图,在第三个活动中检查位图不等于null,然后在第三个活动中设置它