我正在尝试将图像保存到SQL Server,以便SSRS可以读取它。我需要转换为WriteableBitmap(可能还有JPEG?),这样我才能在保存之前更改图像大小。但是,当我尝试将转换后的图像从SQL Server中拉出时,它根本不会在SSRS中呈现。我做错了什么?
byte[] m_Bytes = ReadToEnd(fileStream); //this works fine
WriteableBitmap bmp1 = new WriteableBitmap(166, 166);
bmp1.FromByteArray(m_Bytes); //this works fine
ExtendedImage image = bmp1.ToImage();
MemoryStream stream = new MemoryStream();
ImageTools.IO.Encoders.AddEncoder<JpegEncoder>();
JpegEncoder encoder = new JpegEncoder();
encoder.Encode(image, stream);
BitmapImage img = new BitmapImage();
img.SetSource(stream);
WriteableBitmap bmp2 = new WriteableBitmap(img);
byte[] buffer1 = bmp2.ToByteArray();
CurrentOrder.CompanyImage = buffer1; //this does save a byte array but it will not render in SSRS. If I set buffer1 to bmp1.ToByteArray() then it works fine but I am still unable to resize it using the resize method in WriteableEx without it not rendering in SSRS.
这是对同一件事的另一次尝试,它也不会呈现:
这更简单,也不会起作用:
byte[] m_Bytes = ReadToEnd(fileStream);
WriteableBitmap bmp1 = new WriteableBitmap(166, 166);
bmp1.FromByteArray(m_Bytes);
WriteableBitmap resizedImage = bmp1.Resize(25, 25, WriteableBitmapExtensions.Interpolation.Bilinear);
byte[] buffer1 = resizedImage.ToByteArray();
CurrentOrder.CompanyImage = buffer1;
答案 0 :(得分:1)
你想要的是调整166x166(或25x25)的大小,导出为byte []并从这个字节数组重新加载图片?
您可以尝试使用BitmapImage
吗?
BitmapImage image = new BitmapImage();
image.SetSource(fileStream);
WriteableBitmap bitmap = new WriteableBitmap(image);
WriteableBitmap resizedBitmap = bitmap.Resize(25, 25, WriteableBitmapExtensions.Interpolation.Bilinear);
CurrentOrder.CompanyImage = resizedBitmap.ToByteArray();