利用TakePhoto库选择图片

发布于 2018-03-31  9 次阅读


继承TakePhotoActivity类

拍摄照片

//file
File file = new File(Environment.getExternalStorageDirectory(),
        "/temp/" + System.currentTimeMillis() + ".jpg");
if (!file.getParentFile().exists()) {
    file.getParentFile().mkdirs();
}
Uri imageUri = Uri.fromFile(file);

//take photo
getTakePhoto().onPickFromCapture(imageUri);

重写父类回调方法

@Override
public void takeSuccess(TResult result) {
    String path = result.getImage().getOriginalPath();
    try {
        Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(Uri.fromFile(new File(path))));
        imageView.setImageBitmap(bitmap);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}

@Override
public void takeFail(TResult result, String msg) {
    Toast.makeText(UploadActivity.this, "Error:" + msg, Toast.LENGTH_SHORT).show();
}

@Override
public void takeCancel() {

}