使用没有压缩图像的相机保存图像

时间:2012-10-08 13:25:52

标签: c# android camera

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

 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();



               }
           }
       }
    }

请帮帮我。 感谢。

2 个答案:

答案 0 :(得分:0)

pic.Save("yourfilenamehere.png", ImageFormat.Png);
如果你知道你在文件上写的话,

就足够了(检查Image类保存其他重载的方法)。

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

答案 1 :(得分:0)

谢谢大家。

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

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