2015-09-11 61 views
3

我正在試圖拍照後裁剪遠離照相機的圖像,所以我有這個解決方案時出錯:Android的:加載照片

這是onClick事件來啓動相機

public void onClick(View v) { 

    PackageManager pm = getPackageManager(); 

    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) { 

    Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 

    i.putExtra(MediaStore.EXTRA_OUTPUT, MyFileContentProvider.CONTENT_URI); 

    startActivityForResult(i, CAMERA_RESULT); 

    } else { 

    Toast.makeText(getBaseContext(), "Camera is not available", Toast.LENGTH_LONG).show(); 

    } } 

//這是onActivityResult

@Override 

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

    super.onActivityResult(requestCode, resultCode, data); 

    Log.i(Tag, "Receive the camera result"); 

    if (resultCode == RESULT_OK && requestCode == CAMERA_RESULT) { 

     performCrop(); 

    }else if(requestCode == 5){ 

     String path = this.imageFileUri.getPath(); 
     //Bitmap bit = decodeSampledBitmapFromPath(path, 600, 600); 


    int rotate = 0; 
    try { 
     ExifInterface exif = new ExifInterface(
       this.imageFileUri.getPath()); 
     int orientation = exif.getAttributeInt(
       ExifInterface.TAG_ORIENTATION, 
       ExifInterface.ORIENTATION_NORMAL); 

     switch (orientation) { 
     case ExifInterface.ORIENTATION_ROTATE_270: 
      rotate = 270; 
      break; 
     case ExifInterface.ORIENTATION_ROTATE_180: 
      rotate = 180; 
      break; 
     case ExifInterface.ORIENTATION_ROTATE_90: 
      rotate = 90; 
      break; 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 


    Matrix matrix = new Matrix(); 
    matrix.postScale(0.5f, 0.5f); 
    matrix.postRotate(rotate); 

    // Bitmap bitmap = decodeFile(out); 
    Bitmap bitmap = decodeSampledBitmapFromPath(path, 600, 600); 

    //Bitmap mBitmap = BitmapFactory.decodeFile(out.getAbsolutePath()); 
    bitmap = Bitmap.createBitmap(bitmap, 1, 1, bitmap.getWidth() - 1, bitmap.getHeight() - 1,matrix,true); 



    imageView1.setImageBitmap(bitmap); 

    } 

} 

這是執行作物方法

private void performCrop() { 
    Intent var1 = new Intent("com.android.camera.action.CROP"); 
    File out = new File(getFilesDir(), "newImage.jpg"); 
    if(!out.exists()) { 

      Toast.makeText(getBaseContext(), 

       "Error while capturing image", Toast.LENGTH_LONG) 

       .show(); 

      return;} 
    this.imageFileUri = Uri.fromFile(out); 
    var1.setDataAndType(this.imageFileUri, "image/*"); 
    System.out.println(this.imageFileUri.getPath()); 
    var1.putExtra("crop", "true"); 
    var1.putExtra("scale", true); 
    var1.putExtra("return-data", false); 
    var1.putExtra("output", this.imageFileUri); 
    this.startActivityForResult(var1, 5); 
    } 

目前的問題是,從相機的結果,然後加載裁剪方法後,它顯示加載照片時發生的錯誤。照片編輯器無法啓動。

我看過我的代碼,從這裏一切似乎都沒問題。 請幫助我解決我的問題。

謝謝。

+2

的片段是好的,但「有錯誤發生」是不夠的。也發佈stacktrace。 – Adeeb

+0

在堆棧跟蹤中,不是正式打開的DRM文件。 –

回答