相关疑难解决方法(0)

在wpf中将字节数组转换为图像

我用了

private BitmapImage byteArrayToImage(byte[] byteArrayIn)
{
    try
    {               
        MemoryStream stream = new MemoryStream();
        stream.Write(byteArrayIn, 0, byteArrayIn.Length);
        stream.Position = 0;
        System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
        BitmapImage returnImage = new BitmapImage();
        returnImage.BeginInit();
        MemoryStream ms = new MemoryStream();
        img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
        ms.Seek(0, SeekOrigin.Begin);
        returnImage.StreamSource = ms;
        returnImage.EndInit();

        return returnImage;
    }
    catch (Exception ex)
    {
        throw ex;
    }
    return null;
}
Run Code Online (Sandbox Code Playgroud)

我的应用程序中的此方法将字节数组转换为图像.但它抛出"参数无效"异常..为什么会发生..?有没有其他方法.??

c# wpf

33
推荐指数
3
解决办法
6万
查看次数

在WPF中显示Drawing.Image

我有一个System.Drawing.Image的实例.

如何在我的WPF应用程序中显示这个?

我尝试过,img.Source但这不起作用.

c# wpf image

23
推荐指数
3
解决办法
4万
查看次数

如何使用值转换器将字节数组绑定到WPF中的图像?

我正在尝试将字节数组从我的数据库绑定到WPF图像.

我的XAML:

<Window.Resources>
    <local:BinaryImageConverter x:Key="imgConverter" />
</Window.Resources>
...
<Image Source="{Binding Path=ImageData, Converter={StaticResource imgConverter}}" />
Run Code Online (Sandbox Code Playgroud)

我修改了Ryan Cromwell发布的代码转换代码:

Class BinaryImageConverter
    Implements IValueConverter
    Private Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
        If value IsNot Nothing AndAlso TypeOf value Is Byte() Then
            Dim bytes As Byte() = TryCast(value, Byte())
            Dim stream As New MemoryStream(bytes)
            Dim image As New BitmapImage()
            image.BeginInit()
            image.StreamSource = stream
            image.EndInit()
            Return image
        End If …
Run Code Online (Sandbox Code Playgroud)

.net data-binding wpf xaml image

13
推荐指数
2
解决办法
3万
查看次数

标签 统计

wpf ×3

c# ×2

image ×2

.net ×1

data-binding ×1

xaml ×1