【问题标题】:How to Capture 3 images and display in 3 diff imageview如何捕获 3 张图像并在 3 diff imageview 中显示
【发布时间】:2015-09-15 11:57:02
【问题描述】:

我有 3 个 Imageview。我只想在 android 中捕获 3 个图像并分别显示在 3 个 imageview 中。

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.imageView = (ImageView)this.findViewById(R.id.imageView1);
        this.imageView1 = (ImageView)this.findViewById(R.id.imageView2);
        this.imageView2 = (ImageView)this.findViewById(R.id.imageView3);

        Button photoButton = (Button) this.findViewById(R.id.button1);
        Button photoButton1 = (Button) this.findViewById(R.id.button2);
        Button photoButton2 = (Button) this.findViewById(R.id.button3);

        photoButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(cameraIntent, CAMERA_REQUEST);
            }
        });
    }

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
            Bitmap photo = (Bitmap) data.getExtras().get("data");
            imageView.setImageBitmap(photo);
        }
    }

}

这是我的代码,但我无法在三个 diff 图像视图上设置图像 我的想法是在三个按钮上打开相机并在各自的图像视图上显示图像

【问题讨论】:

  • 你尝试了什么?
  • 请向我们展示您的代码。
  • 它如此简单的用户请求代码作为区分值。您可以检查 onActivityResult 从哪个请求代码活动开始,这也将告诉按钮单击。签入 onActivityResult 这个请求代码并在各自的图像视图上添加图像。

标签: android camera imageview


【解决方案1】:

为每个图像使用不同的请求代码:

photoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, 1);
        }
    });
photoButton1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, 2);
        }
    });

在 Activity 结果集中根据结果设置不同的图像视图:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1 && resultCode == RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);
    }
    if (requestCode == 2 && resultCode == RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView1.setImageBitmap(photo);
    }


}

【讨论】:

  • 感谢另一个问题是如何在文本视图中显示图像下方的图像大小
  • 文件 f = 新文件(文件路径); long fileSizeInBytes = f.length(); long fileSizeInKB = fileSizeInBytes / 1024; long fileSizeInMB = fileSizeInKB / 1024;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-19
  • 1970-01-01
  • 2017-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多