【问题标题】:Get picture data from Image control WPF从Image控件WPF中获取图片数据
【发布时间】:2011-10-21 11:22:49
【问题描述】:

我是 WPF 新手。我正在为 Windows 窗体应用程序编程,并且有带有 Image 属性的图片框。但在 WPF 中有 Image 而不是 Picture Box。如何获得它的价值?我的意思是图像数据。

【问题讨论】:

    标签: c# .net wpf wpf-controls


    【解决方案1】:

    您可以通过使用Image.Source 属性来做到这一点。

    您会在互联网上找到很多关于它的示例。例如下面的代码设置图片来源,同样可以得到图片

    Image myImage3 = new Image();
    BitmapImage bi3 = new BitmapImage();
    bi3.BeginInit();
    bi3.UriSource = new Uri("smiley_stackpanel.PNG", UriKind.Relative);
    bi3.EndInit();
    myImage3.Stretch = Stretch.Fill;
    myImage3.Source = bi3;
    
      //get the source
      BitmapImage imgSource = myImage3.Source;
    

    【讨论】:

    • 接下来呢?我需要创建图片并转换为字节数组
    • @Timur - 我建议你更新问题来这么说;在字节数组中获取图像数据并不是很简单:您是指原始未压缩的图像数据吗?究竟是什么格式?还是您的意思是原始文件数据,可能会被压缩等?
    猜你喜欢
    • 2015-07-02
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    • 1970-01-01
    • 2014-09-11
    • 2019-06-05
    • 1970-01-01
    相关资源
    最近更新 更多