3

写真をキャプチャしてからトリミングしようとしています。つまり、基本的にはカメラ インテントを開始してから、クロップ インテントを開始します。

「onActivityResult」データを介して大きなビットマップを渡すことができないため、画像を直接 SDCard に保存する URI を作成しましたが、何らかの理由で、エミュレーターには保存されていますが、実際のデバイスには保存されていません。(つまり、CROP は実際のデバイスには保存されません。)

これはコードです:

File resultingFile;
Bitmap fotoCreada;
Uri uriFoto;

カメラの意図:

File folder = new File(Environment.getExternalStorageDirectory().toString()+"/PictureFolder/");
folder.mkdirs();
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
resultingFile=new File(folder.toString() + "/"+currentDateandTime+".jpg");
this.uriFoto=Uri.fromFile(resultingFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, this.uriFoto);
startActivityForResult(cameraIntent, 1888); 

次に、結果を取得します。

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    //Si venim de la camera
    if( requestCode == 1888 && resultCode == -1) { //-1 = TOT HA ANAT BE.
        Bitmap photo = BitmapFactory.decodeFile(resultingFile.getPath());
        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        matrix.postScale(0.5f,0.5f);
        Bitmap photoRotated = Bitmap.createBitmap(photo, 0, 0, photo.getWidth(), photo.getHeight(), matrix, true);
        //Desem foto rotada.
        this.fotoCreada=photoRotated;
        try {
            FileOutputStream out = new FileOutputStream(this.resultingFile.getPath());
            this.fotoCreada.compress(Bitmap.CompressFormat.PNG, 90, out);
        } catch (Exception e) {
            e.printStackTrace();
        }
        performCrop();
    }

だから私は performCrop(); を呼び出します。

private void performCrop() {
    try {
        Log.d("debugging","Estic a crop. La foto és:"+this.uriFoto);
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        cropIntent.setDataAndType(this.uriFoto, "image/*");
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
        cropIntent.putExtra("outputX", 600);
        cropIntent.putExtra("outputY", 600);
        //cropIntent.putExtra("return-data", true);
        cropIntent.putExtra("ouput", this.uriFoto);
        startActivityForResult(cropIntent,1234);
    }
    catch(ActivityNotFoundException anfe){
        //display an error message
        String errorMessage = "Whoops - your device doesn't support the crop action!";
        Toast toast = Toast.makeText(this.cont, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }
}

ご覧のように:

cropIntent.putExtra("ouput", this.uriFoto);

基本的にそのURIにクロップを出力するように指示します。私がデバッグしたので、URIは正しいです(LogCat):

作物をエスティックします。写真: file:///mnt/sdcard/PictureFolder/20130123_223058.jpg

そして、アクティビティ結果に戻ります。

[... previous onactivityresult]
if (requestCode == 1234 && resultCode == -1){
        Log.d("debugging","Ha acabat el croop.");
        Uri imageUri = this.uriFoto;
        try {
            Bitmap photo = MediaStore.Images.Media.getBitmap(this.cont.getContentResolver(), imageUri);
            this.fotoCreada=photo;
            ((ImageView) myFragmentView.findViewById(R.id.fotoCapturada)).setImageBitmap(this.fotoCreada);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //Bitmap photo = BitmapFactory.decodeFile(resultingFile.getPath());     
    }

しかし、最終的には、カメラからキャプチャされた画像を (setImageBitmap(this.fotoCreada);) 表示しますが、トリミングされた画像は表示しません。これは実際のデバイスでは発生しますが、エミュレータでは発生しません!

私はできる限り最善の方法で説明しようとしました。遠慮なく尋ねてください。

ありがとう。

4

0 に答える 0