android相机提取位图

时间:2015-09-11 14:07:46

标签: android bitmap camera

我真的需要帮助,我卡住了。 我需要拍摄照片并在程序中使用它的位图,但是我遇到了问题,我尝试了这个代码,但是由于某种原因,结果是一个小得多的图片

Bitmap resultpic=null;

        Intent cameraIntent = new Intent(
                android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI.getPath());
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, "new-photo-name.jpg");
        startActivityForResult(cameraIntent, 1888);

    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        int CAMERA_REQUEST = 1888;
        if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK)
        {
            photo = (Bitmap) data.getExtras().get("data");

            Log.i("phototookwidth",Integer.toString(photo.getWidth()));
            Log.i("phototookheight",Integer.toString(photo.getHeight()));
            File outFile = new File(Environment.getExternalStorageDirectory(), "myname.jpeg");
            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream(outFile);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            photo.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            try {
                fos.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            resultpic=photo;
        }
    }

我有一个代码显示相同的位图,但由于某种原因,尺寸比在同一时间拍摄的照片小10倍,这让我感到困惑,请帮忙

1 个答案:

答案 0 :(得分:0)

not spanspan.icon

类似这样的错误检查语句