ABOUT_time 2015-03-04 10:15 采纳率: 0%
浏览 9512

Android 进入剪切图片界面异常,提示无法加载图片,然后退出

这是我的代码,大神门错在哪,求教~
拍照功能正常,进入剪切界面就闪退。
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;
    }

}
  • 写回答

5条回答

  • 遨翼 2015-03-05 01:43
    关注

    看看设备自带的相机是否是先剪切后保存
    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);

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮