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);

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘