保存从相机拍摄的图像而不压缩

Saving image taken from camera without compression

我正在使用此方法将从相机拍摄的图像保存到内部存储器:

public String saveImage(Bitmap myBitmap) {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
     myBitmap.compress(Bitmap.CompressFormat.JPEG,100,bytes);
        File wallpaperDirectory = new File(
                Environment.getExternalStorageDirectory() + IMAGE_DIRECTORY);
        // have the object build the directory structure, if needed.
        if (!wallpaperDirectory.exists()) {
            wallpaperDirectory.mkdirs();
        }

        try {
            File f = new File(wallpaperDirectory, Calendar.getInstance()
                    .getTimeInMillis() + ".jpg");
            f.createNewFile();
            FileOutputStream fo = new FileOutputStream(f);
            fo.write(bytes.toByteArray());
            MediaScannerConnection.scanFile( getActivity(),
                    new String[]{f.getPath()},
                    new String[]{"image/jpeg"}, null);
            fo.close();
            Log.d("TAG", "File Saved::--->" + f.getAbsolutePath());

            return f.getAbsolutePath();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return "";
    }

存储的图像大小约为 15.24 kB,但在未使用我的应用程序的情况下从相机拍摄的相同图像的大小为 3.59MB。 我需要在不压缩或压缩较小的情况下存储来自我的应用程序的图像。

我做错了什么?

编辑

我猜问题出在 onActiciyResult 的这一部分:

if (requestCode == 7 && resultCode == RESULT_OK) {

            Bitmap bitmap = (Bitmap) data.getExtras().get("data");




            selectedFilePath = saveImage(bitmap);





            fotoActual.setImageBitmap(bitmap);
            nombreArchivo.setText( selectedFilePath);
            dialog = ProgressDialog.show(getActivity(),"","Subiendo foto ...",true);

            new Thread(new Runnable() {
                @Override
                public void run() {
                    //creating new thread to handle Http Operations
                    uploadFile(selectedFilePath);
                }
            }).start();
        }

使用 Bitmap bitmap = (Bitmap) data.getExtras().get("data"); returns 缩略图而不是图像。

您必须在启动相机时从文件中指定 URI,如下所示:

    Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    File wallpaperDirectory = new File(
            Environment.getExternalStorageDirectory() + IMAGE_DIRECTORY);

    myFile = new File(wallpaperDirectory, "MyPhoto.jpeg");
    i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(myFile)); --> you have to do this

    startActivityForResult(i, CONTENT_REQUEST);

这样做,您不需要在 Activity 结果上调用 saveImage。