简体   繁体   English

从ImageView获取图像并将其转换为system.Drawing的位图

[英]get Image from ImageView and convert it to Bitmap of system.Drawing

我想将ImageView中的Image转换为System.Drawing的位图以在代码或函数中使用它接受system.Drawing的位图而不是Android.Graphics的位图。

I guess you want to use the Source of ImageView as like the Bitmap 我想你想像位图一样使用ImageView的源代码

Suppose: 假设:

Source of ImageView is filepath1, where the filepath1 is a file path string standing for a jpg file. ImageView的来源是filepath1,其中filepath1是代表jpg文件的文件路径字符串。

Then you can try the following code: 然后,您可以尝试以下代码:

if (file != null)
        {
            byte[] imageBytes;
            var FileImage = new Image();

            string base64;
            using (var fs = new FileStream(file.FilePath, FileMode.Open, FileAccess.Read))
            {
                var buffer = new byte[fs.Length];
                fs.Read(buffer, 0, (int)fs.Length);
                base64 = Convert.ToBase64String(buffer);
            }

            imageBytes = Convert.FromBase64String(base64); 
            File.WriteAllBytes(filename, imageBytes);
            var bitmap = new Image { Source = filename};

            imgViewer2.Source = bitmap.Source;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM