这是我的代码,大神门错在哪,求教~
拍照功能正常,进入剪切界面就闪退。
public class informationActivity extends Activity {
public static final int TAKE_PHOTO = 1;
public static final int CROP_PHOTO = 2;
private Button takephoto;
private ImageView picture;
private Uri uri;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.information);
dbHelper = new MySQLiteHelper(this,"StudentData4.db",null, 1);
takephoto = (Button) findViewById(R.id.takephoto);
picture = (ImageView)findViewById(R.id.picture);
takephoto.setOnClickListener(new OnClickListener(){
public void onClick(View v){
File outputImage = new File(Environment.getExternalStorageDirectory(),"out_image.jpg");
try{
if(outputImage.exists()){
outputImage.delete();
}
outputImage.createNewFile();
}catch(IOException e){
e.printStackTrace();
}
uri = Uri.fromFile(outputImage);
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra("MediaStore.EXTRA_OUTPUT", uri);
startActivityForResult(intent,TAKE_PHOTO);
}
});
}
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data){
switch (requestCode){
case TAKE_PHOTO:
if(resultCode == RESULT_OK){
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
intent.putExtra("scale", true);
intent.putExtra("MediaStore.EXTRA_OUTPUT", uri);
startActivityForResult(intent,CROP_PHOTO);
}
break;
case CROP_PHOTO:
if(resultCode == RESULT_OK){
try{
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
picture.setImageBitmap(bitmap);
}catch(FileNotFoundException e){
e.printStackTrace();
}
}
break;
default:
break;
}
}