简体   繁体   中英

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

Suppose:

Source of ImageView is filepath1, where the filepath1 is a file path string standing for a jpg file.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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