这是我的代码,大神门错在哪,求教~
拍照功能正常,进入剪切界面就闪退。
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;
}
}
看看设备自带的相机是否是先剪切后保存
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1.6);
intent.putExtra("aspectY", 1);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(FileUtil
.createFile(picPath + applicationId + "_"
+ photoPathIndex + ".jpg")));
startActivityForResult(intent, photoPathIndex);
我也是 。 第一行代码。。
请问这个问题解决了吗?我也是照书上代码看到这里, 不知道为什么会出错了
请问楼主这个解决了吗?
我也是这个问题哦,拍照那部分是拍了能正常剪切但也是显示不了在imageview上。而且查看内存outputimage-jpg是0kb的,也就是说拍完照后还有剪切后的照片都没有保存在设置的指定地方。