2012-09-28 2 views
1

사진을 찍는 기능이 있습니다. 사용자는 카메라 또는 갤러리에서 사진을 찍을 수 있습니다. 사용자가 사진을 선택하면 해당 사진이 다른 활동에 표시됩니다. 다른 활동에서 사용자는이 그림을 편집 할 수 있습니다. 이 경우 이미지 자르기 기능을 만들고 싶습니다. 그러나 달리는 때, 나는 작물을 선택하고, 아무 일도 일어나지 않습니다. 제게 해결책을주세요. 이 내 코드안드로이드 이클립스 자르기 이미지

package shoop3.android.edu; 

import java.io.File; 

import java.util.ArrayList; 
import java.util.List; 

import android.app.Activity; 
import android.app.AlertDialog; 

import android.content.ActivityNotFoundException; 
import android.content.ComponentName; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.content.pm.ResolveInfo; 

import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.provider.MediaStore; 
import android.view.View; 

import android.net.Uri; 

import android.os.Bundle; 
import android.os.Environment; 

import android.widget.Button; 
import android.widget.ArrayAdapter; 
import android.widget.Toast; 
import android.widget.ImageView; 

public class editorActivity extends Activity { 
    private Uri mImageCaptureUri; 
    private ImageView mImageView; 


    private static final int CROP= 1; 
    private static final int HASIL_CROP = 2; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.editor); 

     ImageView imageeditor = (ImageView)findViewById(R.id.ImageViewEditor); 
     Intent hasil = getIntent(); 

     String path = hasil.getStringExtra("pathimage"); 
     mImageCaptureUri = hasil.getData(); 
     //Bitmap b = (Bitmap) getIntent().getParcelableExtra("mImageView"); 
     imageeditor.setImageBitmap(BitmapFactory.decodeFile(path)); 

     final String [] items   = new String [] {"CROP"};    
     ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, android.R.layout.select_dialog_item,items); 
     AlertDialog.Builder builder  = new AlertDialog.Builder(this); 

     builder.setTitle("Image Editor"); 
     builder.setAdapter(adapter, new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int item) { 

       if(item == 0){ 
       Intent i = getIntent(); 
       mImageCaptureUri = i.getData(); 
       startActivityForResult(i, CROP); 
       } 


       } 

     }); 

     final AlertDialog dialog = builder.create(); 

     //Button button  = (Button) findViewById(R.id.btn_crop); 
     mImageView  = (ImageView) findViewById(R.id.ImageViewEditor); 
     mImageView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       dialog.show(); 
      } 
     }); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (resultCode != RESULT_OK) return; 

     switch (requestCode) { 


      case CROP: 
       mImageCaptureUri = data.getData(); 

       doCrop(); 

       break;   

      case HASIL_CROP:    
       Bundle extras = data.getExtras(); 

       if (extras != null) {    
        Bitmap photo = extras.getParcelable("data"); 

        mImageView.setImageBitmap(photo); 
       } 

       File f = new File(mImageCaptureUri.getPath());    

       if (f.exists()) f.delete(); 

       break; 

     } 
    } 

    private void doCrop() { 

     try{ 
      Intent cropintent = new Intent("com.android.action.CROP"); 
      cropintent.setDataAndType(mImageCaptureUri, "/image/*"); 
      cropintent.putExtra("crop", true); 
      cropintent.putExtra("aspectX", 1); 
      cropintent.putExtra("aspectY", 1); 
      cropintent.putExtra("outputX", 256); 
      cropintent.putExtra("outputY", 256); 
      cropintent.putExtra("return-data", true); 
      startActivityForResult(cropintent, HASIL_CROP); 
     }catch(ActivityNotFoundException e){ 
      String errorMessage = "Your device not Support"; 
      Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT).show(); 
     } 

    }} 
+0

잠금 http://stackoverflow.com/questions/3846338/how-to-crop-an-image-in- android – Pasha

+0

가능한 경우 관련 코드 만 게시하려고합니다. – keyser

답변

-1

이 줄을 사용중인 작물 방법 :

 Intent cropintent = new Intent("com.android.action.CROP"); 

모든 안드로이드 장치를 지원하지 않습니다. 나는이 문제를 겪고 있으며, 나 자신을 위해서도 그것을 해결하려고 노력하고있다.

당신이 카메라를 잊어 편집 당신의 문제가 바로 될 수 있습니다

이에서
 Intent cropintent = new Intent("com.android.camera.action.CROP");