如何在Android画廊展示相机?

时间:2014-01-22 11:36:11

标签: android

Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI); 
startActivityForResult(i, 2); 

当我使用这些行从我的设备库中选择图像时,默认情况下取消按钮显示在我的设备库屏幕的标题栏上。在取消按钮的地方我希望显示相机图像请任何人建议我如何显示相机

2 个答案:

答案 0 :(得分:1)

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

                }
            });
            frmalbumb.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent int_album = new Intent(Intent.ACTION_PICK);
                    int_album.setType("image/*");
                    startActivityForResult(int_album, 2);

                }
            });




            @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == RESULT_OK) {

            Bitmap photo = (Bitmap) data.getExtras().get("data");
            imgview.setImageBitmap(photo);

        } else if (requestCode == 2 && resultCode == RESULT_OK) {

            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };
            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            File file = new File(picturePath);
            Bitmap bmpp = decodeAndResizeFile(file);
            imgview.setImageBitmap(bmpp);


        }
    }



    public Bitmap decodeAndResizeFile(File f) {
        try {
            // Decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;
            BitmapFactory.decodeStream(new FileInputStream(f), null, o);

            // The new size we want to scale to
            final int REQUIRED_SIZE = 70;

            // Find the correct scale value. It should be the power of 2.
            int width_tmp = o.outWidth, height_tmp = o.outHeight;
            int scale = 1;
            while (true) {
                if (width_tmp / 2 < REQUIRED_SIZE
                        || height_tmp / 2 < REQUIRED_SIZE)
                    break;
                width_tmp /= 2;
                height_tmp /= 2;
                scale *= 2;
            }
            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
        } catch (FileNotFoundException e) {
        }
        return null;
    }

答案 1 :(得分:0)

AFAIK相机应用程序布局独立于其他应用程序。它将根据设备和API进行更改。您无法更改默认相机应用程序的布局设计。

如果您愿意,可以创建自己的布局并自行打开相机。