0

我正在尝试创建一个应用程序,用户可以在其中使用相机拍照并将其保存到指定文件夹。但是,当它从 imageView 转换为 PNG 文件时,质量会显着下降。

我认为使用这段代码可以确保质量保持高水平

bmap.compress(Bitmap.CompressFormat.PNG, 100, output);

但即使我将质量从 100 更改为更低的数字,我也看不出有任何区别。

if (requestCode == cameraData && resultCode == RESULT_OK
            && null != data) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");

        ImageView imageView = (ImageView) findViewById(R.id.imgView);
        imageView.setImageBitmap(photo);

        // convert imageview to bitm
        imageView.buildDrawingCache();
        final Bitmap bmap = imageView.getDrawingCache();

        addIt.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                OutputStream output;

                // Find the SD Card path
                File filepath = Environment.getExternalStorageDirectory();

                // Create a new folder AndroidBegin in SD Card
                File dir = new File(filepath.getAbsolutePath()
                        + "/filepath1/");
                dir.mkdirs();

                // Create a name for the saved image
                File file = new File(dir, "image.png");

                // Notify the user on successful save
                Toast.makeText(Images.this, "Image Saved to SD Card",
                        Toast.LENGTH_SHORT).show();
                try {

                    // Image starts saving
                    output = new FileOutputStream(file);

                    // Compress into png format image from 0% - 100%, using
                    // 100% for this tutorial
                    bmap.compress(Bitmap.CompressFormat.PNG, 100, output);

                    output.flush();
                    output.close();

                    Intent myIntent = new Intent(Images.this,
                            MyPreferencesActivity.class);
                    startActivity(myIntent);
                }

                // Catch exceptions
                catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
4

1 回答 1

1

称呼

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

仅返回图像的缩略图。按照本教程从相机保存图像:http: //developer.android.com/training/camera/photobasics.html

于 2013-04-24T20:05:18.867 回答