【问题标题】:captured image quality reduced拍摄的图像质量降低
【发布时间】:2018-06-19 23:35:49
【问题描述】:

在我的应用程序中使用相机拍摄的图片保存在外部存储的文件夹中。当我检查文件夹时,我发现它的质量低于画廊中的相同图像。使用 FileOutputStream 我将图像保存到文件夹。有没有其他方法可以在不损失质量的情况下保存图像?下面是我的代码:

将捕获的图像保存到文件夹的代码:

    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode==2&&resultCode==RESULT_OK)
            {
                File camerafile=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/CameraTestFile");
                if (!camerafile.exists())
                {
                    camerafile.mkdir();
                    Toast.makeText(getApplicationContext(),"Folder created",Toast.LENGTH_SHORT).show();
                }
                else
                    {
                    Toast.makeText(getApplicationContext(),"Folder already exists ",Toast.LENGTH_SHORT).show();
                }
                Bitmap bitmap;
                bitmap= (Bitmap) data.getExtras().get("data");
                ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG,100,byteArrayOutputStream);

                try {

                    FileOutputStream fileOutputStream=new FileOutputStream(camerafile+"/camera3.png");
                    fileOutputStream.write(byteArrayOutputStream.toByteArray());
                    fileOutputStream.close();

                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                }
        }

【问题讨论】:

标签: android camera fileoutputstream


【解决方案1】:

参考我在https://stackoverflow.com/a/50929913/9882512的回答>

您可以使用鳕鱼。只需更改文件的路径。它会直接将文件保存到所需位置,无需复制文件

 File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                        String pictureName = getPictureName();
                        imagefile = new File(pictureDirectory, pictureName);
                        picUri = Uri.fromFile(imagefile);
                        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, picUri);
                        startActivityForResult(cameraIntent, CAMERA_REQUEST);

【讨论】:

    猜你喜欢
    • 2019-10-06
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 2019-08-23
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    相关资源
    最近更新 更多