使用相机保存图像而不压缩图像



在我的应用程序中,我想用相机拍照并将它们保存在文件中。照片质量在我的应用程序中非常重要,因此当我压缩以保存它时,图像质量会丢失。这是我的代码:

 protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
       base.OnActivityResult(requestCode, resultCode, data);
        FileOutputStream outStream = null;
       saveFullImage();
       if ((requestCode == TAKE_PICTURE))
       {
           if (data != null)
           {
               if (data.HasExtra("data"))
               { 
                   Bitmap pic = (Bitmap)data.Extras.Get("data");

                   System.IO.MemoryStream baos = new System.IO.MemoryStream();
                   pic.Compress(Bitmap.CompressFormat.Png, 100, baos);
                   byte[] byte_img_data = baos.ToArray();
                   outStream = new FileOutputStream(outputFileUri.Path);
                   outStream.Write(byte_img_data);
                   outStream.Close();

               }
           }
       }
    }

请帮助我。谢谢。

pic.Save("yourfilenamehere.png", ImageFormat.Png);

如果您知道自己在文件上写入,应该就足够了(检查 Image 类 Save 方法以了解其他重载)。

这种

压缩是无损的,因此您不应该以这种方式丢失任何细节。

谢谢大家。

使用以下代码不会更改图片详细信息:

var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
var contentUri = Android.Net.Uri.FromFile(_file);
mediaScanIntent.SetData(contentUri);
this.SendBroadcast(mediaScanIntent);

最新更新