如何转换system.windows.control.image"“;System.Drawing.Image

本文关键字:quot System Image Drawing image control 何转换 转换 windows system | 更新日期: 2023-09-27 18:09:54

你好,朋友们,我想转换一个system.windows.control。image"改为"System.Drawing"。图像",但我不能这样做。我使用下面的代码为这个

var e = (MouseButtonEventArgs)sender;
var device = e.MouseDevice.DirectlyOver;
System.Windows.Controls.Image img = (System.Windows.Controls.Image)device;

我有"img",即类型为"system.windows.control"。图像"我需要将其转换为位图或绘图类型

如何转换system.windows.control.image"“;System.Drawing.Image

试试这个....

在此代码中使用您的img变量…

MemoryStream ms = new MemoryStream(); 
System.Windows.Media.Imaging.BmpBitmapEncoder bbe = new BmpBitmapEncoder();
bbe.Frames.Add(BitmapFrame.Create(new Uri(img.Source.ToString(),UriKind.RelativeOrAbsolute)));
bbe.Save(ms); 
System.Drawing.Image img2 = System.Drawing.Image.FromStream(ms); 
button1.Image = img2;

convert from byte[] to image

 MemoryStream ms = new MemoryStream(imageByte);
    Image image = Image.FromStream(ms);
相关文章: