【问题标题】:How to use Camera Intent with Crop Intent both at one Intent in Webview如何在 Webview 的一个 Intent 中同时使用 Camera Intent 和 Crop Intent
【发布时间】:2016-05-31 14:17:08
【问题描述】:

我关注this 使用网络视图中的相机..上传,,,

所以我得到了默认相机..我正在捕捉..和上传...

所以我想裁剪它们……然后上传……最大 2 兆像素分辨率不超过 2Mp……

我关注this使用Crop...

我可以在 web 视图中同时使用这两个意图......并且分辨率应该很低.. 我的意思是在捕获后它应该显示crop...选项...然后上传,,,

谁能推荐我...

【问题讨论】:

    标签: android android-intent webview camera crop


    【解决方案1】:
    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;
        }
    }
    

    使用此代码通过裁剪功能从相机或图库中拍摄照片。希望对你有帮助

    【讨论】:

    • 谢谢@New Coder 但是你能告诉我如何在Webview中使用它...点击...它应该发生并上传...一旦检查...androidexample.com/…跨度>
    • 先生曾经告诉我...如何在网络视图中添加此内容...在此应用程序中androidexample.com/… 请更新您的答案
    • 在onclick里面调用pickimage()方法
    • 先生,我正在使用这个 webView.setWebChromeClient(new WebChromeClient() { // openFileChooser for Android 3.0+ public void openFileChooser(ValueCallback uploadMsg, String acceptType){ // 更新消息 mUploadMessage = uploadMsg ; 建议我在 chromium webview 上做什么
    • 先生它来自 webview 先生一旦检查并请更新您的答案先生...我会支持,,,
    猜你喜欢
    • 1970-01-01
    • 2012-11-03
    • 2015-07-14
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-14
    相关资源
    最近更新 更多