Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用c#wpf从数据库检索和上传图像有没有最短的方法?_C#_Wpf_Image Processing_Image Uploading_Argumentexception - Fatal编程技术网

使用c#wpf从数据库检索和上传图像有没有最短的方法?

使用c#wpf从数据库检索和上传图像有没有最短的方法?,c#,wpf,image-processing,image-uploading,argumentexception,C#,Wpf,Image Processing,Image Uploading,Argumentexception,我有下面的代码,它可以正常工作。我试图从教程中的数据库上传和检索图像,但当我使用数据库中的数据修改图像时,它会一直显示此部分的参数异常 System.Drawing.Image img = System.Drawing.Image.FromStream(stream); 错误为forsystem.drawing dll 它可以上传,但不能显示上传的图像 如果我不能解释这些问题,请告诉我。谢谢中间系统.绘图.图像是多余的。您可以通过以下方式直接从blob加载位图图像: BitmapImage b

我有下面的代码,它可以正常工作。我试图从教程中的数据库上传和检索图像,但当我使用数据库中的数据修改图像时,它会一直显示此部分的参数异常

System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
错误为for
system.drawing dll

它可以上传,但不能显示上传的图像


如果我不能解释这些问题,请告诉我。谢谢

中间
系统.绘图.图像
是多余的。您可以通过以下方式直接从
blob
加载位图图像:

BitmapImage bi = new BitmapImage();

using (var stream = new MemoryStream(blob))
{
    bi.BeginInit();
    bi.CacheOption = BitmapCacheOption.OnLoad;
    bi.StreamSource = stream;
    bi.EndInit();
}

image2.Source = bi;

中间
系统.Drawing.Image
是冗余的。您可以通过以下方式直接从
blob
加载位图图像:

BitmapImage bi = new BitmapImage();

using (var stream = new MemoryStream(blob))
{
    bi.BeginInit();
    bi.CacheOption = BitmapCacheOption.OnLoad;
    bi.StreamSource = stream;
    bi.EndInit();
}

image2.Source = bi;

你好我尝试了你的代码,但现在它显示了这个错误。未找到适合完成此操作的成像组件。我在一行中找到了它,上面写着bi.EndInit(),这意味着
blob
中的字节数组不包含有效的编码位图帧,即没有PNG、JPEG、BMP等。从数据库读取时可能出了问题。您好!我尝试了你的代码,但现在它显示了这个错误。未找到适合完成此操作的成像组件。我在一行中找到它,上面写着bi.EndInit(),这意味着
blob
中的字节数组不包含有效的编码位图帧,即没有PNG、JPEG、BMP等。从数据库中读取时可能出了问题。