簡體   English   中英

如何在Webview中同時使用相機意圖和作物意圖

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

我按照此步驟從網絡視圖使用相機。

因此,我正在獲取默認相機..並且正在捕獲..並正在上載...

所以我想裁剪它們並上傳..最大2百萬像素分辨率不超過2Mp ...

我跟隨這個來使用作物...

我有可能在網絡視圖中同時使用這兩種方法,而且分辨率應該很低。.我的意思是,捕獲后,它應該顯示出...選項,然后上傳、、

誰能建議我...

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;
    }
}

使用此代碼可從具有裁剪功能的相機或圖庫中拍攝照片。 希望對你有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM