1

我有一个相机拍照方法,它会像这样拍照:

public void takePicture() {
        InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

        inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

        cameraHelper = new CameraHelper();
        cameraHelper.initialize(this, this.getApplicationContext(), CAPTURED_IMAGE_PATH);
        Intent imageIntent = cameraHelper.dispatchTakePictureIntent(CameraHelper.ACTION_TAKE_PHOTO_B);


        startActivityForResult(imageIntent, CameraHelper.ACTION_TAKE_PHOTO_B);

    }

用户完成拍摄并保存照片后,我尝试获取结果并调整大小并压缩它。这是我的活动结果:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {


        if (requestCode == CameraHelper.ACTION_TAKE_PHOTO_B || requestCode == CameraHelper.ACTION_TAKE_PHOTO_S) {

            File f = cameraHelper.onActivityResult(requestCode, resultCode, data);

            if (f != null) {

                try{
                    Log.i("PHOTO", "Start to resize");
                    Bitmap b = BitmapFactory.decodeStream(getAssets().open(f.getAbsolutePath()));
                    Log.i("PHOTO", "orginal width : "+b.getWidth()+", original height : "+b.getHeight());
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    Bitmap resized = Bitmap.createScaledBitmap(b, b.getWidth()/2, b.getHeight()/2, true);
                    Log.i("PHOTO", "Resize width : "+resized.getWidth()+", Resize height : "+resized.getHeight());
                    resized.compress(Bitmap.CompressFormat.JPEG, 100, out);
                    Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
                    Log.i("PHOTO", "Compress width : "+decoded.getWidth()+", Compress height : "+decoded.getHeight());

                }catch(Exception e){
                    Log.i("PHOTO", e.toString());
                }


            } else {
                Toast.makeText(this, "F IS NULL", Toast.LENGTH_SHORT).show();
            }

        }
    }

但是:(有错误,这是日志:

07-30 13:57:01.149: I/PHOTO(28841): Start to resize
07-30 13:57:01.154: I/PHOTO(28841): java.io.FileNotFoundException: file://storage/sdcard0/Pictures/imotax/capture/spop/IMG_20130730_135655_98370721.jpg

请帮帮我..解决这个问题,它还可以调整图像大小和压缩图像。多谢你们

4

0 回答 0