简体   繁体   English

如何在Webview中同时使用相机意图和作物意图

[英]How to use Camera Intent with Crop Intent both at one Intent in Webview

I followed this to use camera from web-view..with upload,,, 我按照此步骤从网络视图使用相机。

So in that I am getting Default camera.. and I am capturing.. and Uploading... 因此,我正在获取默认相机..并且正在捕获..并正在上载...

So I want to Crop them...and Upload.. with Max 2 Megapixel resolution not more than 2Mp... 所以我想裁剪它们并上传..最大2百万像素分辨率不超过2Mp ...

I followed this to use Crop... 我跟随这个来使用作物...

I it Possible to use both intents together in web-view... and resolution should be low.. I mean after capture it should show crop... option... and then upload,,, 我有可能在网络视图中同时使用这两种方法,而且分辨率应该很低。.我的意思是,捕获后,它应该显示出...选项,然后上传、、

Can any one suggest me... 谁能建议我...

private void pickImage() {
    AlertDialog.Builder builder = new AlertDialog.Builder(Create_event.this);
    builder.setTitle("Choose Image");
    builder.setMessage("Select Image");
    builder.setPositiveButton("Gallery",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent photoPickerIntent = new Intent(
                            Intent.ACTION_PICK);
                    photoPickerIntent.setType("image/*");
                    startActivityForResult(photoPickerIntent, 1);
                    dialog.dismiss();
                }
            });
    builder.setNegativeButton("Camera",
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent cameraIntent = new Intent(
                            android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(cameraIntent, 2);
                    dialog.dismiss();
                }
            });
    builder.show();
}

private Uri getTempUri() {
    return Uri.fromFile(getTempFile());
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == 2 || requestCode == 1) {
            try {
                Intent cropIntent = new Intent(
                        "com.android.camera.action.CROP");
                // indicate image type and Uri
                cropIntent.setDataAndType(data.getData(), "image/*");
                cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
                cropIntent.putExtra("outputFormat",
                        Bitmap.CompressFormat.JPEG.toString());
                // set crop properties
                cropIntent.putExtra("crop", "true");
                // indicate aspect of desired crop
                cropIntent.putExtra("aspectX", 1);
                cropIntent.putExtra("aspectY", 1);
                // indicate output X and Y
                cropIntent.putExtra("outputX", 256);
                cropIntent.putExtra("outputY", 256);
                // retrieve data on return
                cropIntent.putExtra("return-data", true);
                // start the activity - we handle returning in
                // onActivityResult
                startActivityForResult(cropIntent, 3);
            } catch (ActivityNotFoundException anfe) {
                // display an error message
                String errorMessage = "Whoops - your device doesn't support the crop action!";
                Toast toast = Toast.makeText(this, errorMessage,
                        Toast.LENGTH_SHORT);
                toast.show();
            }
        } else if (requestCode == 3) {
            try {
                Log.e("testing", "return data is  " + data.getData());

                String filePath = Environment.getExternalStorageDirectory()
                        + "/" + TEMP_PHOTO_FILE;
                System.out.println("path " + filePath);
                uImage = BitmapFactory.decodeFile(filePath);
                ByteArrayOutputStream bao = new ByteArrayOutputStream();
                uImage.compress(Bitmap.CompressFormat.PNG, 100, bao);
                ba = bao.toByteArray();
                ivcreateeventflyer.setImageBitmap(uImage);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}

private static final String TEMP_PHOTO_FILE = "temporary_holder.jpg";

private File getTempFile() {

    if (Environment.getExternalStorageState().equals(
            Environment.MEDIA_MOUNTED)) {

        File file = new File(Environment.getExternalStorageDirectory(),
                TEMP_PHOTO_FILE);
        try {
            file.createNewFile();
        } catch (IOException e) {
        }

        return file;
    } else {

        return null;
    }
}

Use this code to take pic from camera or gallery with crop functionality. 使用此代码可从具有裁剪功能的相机或图库中拍摄照片。 hope it may be help you 希望对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM