我有一个WPF应用程序,我在其中上传AutoCAD图纸文件(.dwg),将其转换为字节数组并保存到数据库中。当我从字节数组中读取该文件时,我遇到了以下错误:
No imaging component suitable to complete this operation was found.
我用以下代码将其转换为字节数组:
FileStream fs = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
我正在尝试使用以下代码从字节数组中获取图像:
```java byte[] imageData = ...; Image image = ImageIO.read(new ByteArrayInputStream(imageData)); ```
请注意,上述代码需要使用Java ImageIO库。
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.CreateOptions = BitmapCreateOptions.None;
bi.CacheOption = BitmapCacheOption.Default;
bi.StreamSource = new MemoryStream(data);
RenderOptions.SetBitmapScalingMode(bi, BitmapScalingMode.Linear);
bi.EndInit();
以上代码对于像jpg、png、bmp、gif这样的其他图像文件可以正常工作,但对于dwg文件却无法正常工作。有人能指导我我的代码有什么问题吗?
谢谢。