如何在 Xamarin Android 中使用其原始 dpi 值保存图像?

问题描述

这是我的原始图像属性。

Original Image

我正在使用下面的代码来保存图像。

private void Button_Click(object sender,System.EventArgs e)
    {
        var image = Resource.Mipmap.DSC_0005;
        var bitmap = BitmapFactory.DecodeResource(Resources,image);
      // Scaled the bitmap in the actual image size
       // bitmap = Bitmap.CreateScaledBitmap(bitmap,6000,4000,false);
        string filePath;
        var file =
       new Java.IO.File(
           Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures)
               .ToString());
        if (!file.Exists())
            file.Mkdir();
        filePath = System.IO.Path.Combine(file.ToString(),"Image" + System.DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + "jpg");
        if (System.IO.File.Exists(filePath))
            System.IO.File.Delete(filePath);
       

        using (var fileStream = new FileStream(filePath,FileMode.CreateNew))
        {
            bitmap?.Compress(Bitmap.CompressFormat.Jpeg,97,fileStream);
        }
       
        var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
        Java.IO.File f = new Java.IO.File(filePath);
        Uri contentUri = Uri.FromFile(f);
        mediaScanIntent.SetData(contentUri);
        Application.Context.SendBroadcast(mediaScanIntent);
    }

保存图像后,我得到以下属性。

After saving the image

现在保存图像中的水平和垂直分辨率 DPI 值已更改。

我想用相同的 DPI 值保存图像。如何保存相同 DPI 值的图像?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)