2013-03-31 20 views
0

我想在我的Android平板電腦中裁剪,但它不工作。裁剪不顯示圖像和不工作 - android

我使用的是Nexus 10

嗯......這是我的裁剪代碼:

private void doCrop(){ 
    Intent intent = new Intent("com.android.camera.action.CROP"); 
    intent.setDataAndType(mImageCaptureUri, "image/*"); 
    List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, 0); 
    int size = list.size(); 
    if (size == 0) {    
     Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show(); 
     return; 
    } else { 
     intent.setData(mImageCaptureUri);   
     intent.putExtra("outputX", 648); 
     intent.putExtra("outputY", 486); 
     intent.putExtra("aspectX", 1); 
     intent.putExtra("aspectY", 1); 
     intent.putExtra("scale", true); 
     intent.putExtra("return-data", true); 
     if (size == 1) { 
      Intent i  = new Intent(intent); 
      ResolveInfo res = list.get(0); 
      i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); 
      startActivityForResult(i, CROP_RESULT); 
     } else { 
     } 

    } 
} 

這裏是我的對話框,要求「相機」或「畫廊「:

private void startDialog() { 
    AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this); 
    myAlertDialog.setTitle("Selecione uma foto!"); 
    myAlertDialog.setMessage("Choose a source"); 

    myAlertDialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface arg0, int arg1) { 
      pictureActionIntent = new Intent(Intent.ACTION_GET_CONTENT, null); 
      pictureActionIntent.setType("image/*"); 
      pictureActionIntent.putExtra("return-data", true); 
      startActivityForResult(pictureActionIntent, GALLERY_PICTURE); 
     } 
    }); 

    myAlertDialog.setNegativeButton("Camera", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface arg0, int arg1) { 
      pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
      storagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp/android.jpg"; 
      pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, storagePath); 
      startActivityForResult(pictureActionIntent, CAMERA_PICTURE); 
     } 
    }); 
    myAlertDialog.show(); 
}  

的d這裏是我的onActivityResult:

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    Bitmap bmp; 
    if (resultCode == RESULT_OK){ 
     switch (requestCode){ 
     case GALLERY_PICTURE : 
      mImageCaptureUri = data.getData(); 
      doCrop(); 
     break; 
     case CROP_RESULT : 
      Bundle extras = data.getExtras(); 
      if (extras != null) {    
       bmp = extras.getParcelable("data"); 
       bmp = Bitmap.createScaledBitmap(bmp, 648, 486, true); 
       Drawable d = new BitmapDrawable(getResources(),bmp); 
       btnTitular.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null); 
      } 
      File f = new File(mImageCaptureUri.getPath());    
      if (f.exists()) f.delete(); 
      Intent inten3 = new Intent(this, CadTitularActivity.class); 
      startActivity(inten3); 
     break; 
     case CAMERA_PICTURE : 
      doCrop(); 
     break; 
     } 
    }   
} 

這裏是正在發生的事情:

當我抓住從畫廊的圖像,作物是表演,但是當我點擊「確定」作物形象,它什麼都不做。

當我從相機抓取圖片時,它什麼都不做。它只顯示「加載圖片」,沒有任何反應。

任何想法?

記住:我正在使用Nexus 10.我已經聽說這種裁剪的東西不適用於所有設備。

歡迎任何幫助!

謝謝!

回答

0

我認爲問題是作物意圖必須設置爲輸出x和y的256 x 256(或更少)。

所以代碼從:

intent.putExtra("outputX", 648); 
intent.putExtra("outputY", 486); 

這樣:

intent.putExtra("outputX", 256); 
intent.putExtra("outputY", 256); 

應該再爲你工作。