[英]Converting FileStream to WriteableBitmap to JPEG to Byte Array for SSRS
I'm trying to save an Image to SQL Server so SSRS can read it. 我正在尝试将图像保存到SQL Server,以便SSRS可以读取它。 I need to convert to WriteableBitmap (and possibly JPEG?) so I can make changes to the image size before saving.
我需要转换为WriteableBitmap(甚至是JPEG?),以便可以在保存之前更改图像大小。 However, when I try to pull the converted image out of SQL Server, it will not render in SSRS at all.
但是,当我尝试将转换后的图像从SQL Server中拉出时,它根本不会在SSRS中呈现。 What am I doing wrong?
我究竟做错了什么?
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.
This is another try at the same thing and it won't render either: 这是对同一件事的另一种尝试,它也不会呈现:
And this is simpler and won't work either: 而且这更简单,也不起作用:
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;
What you want is to resize 166x166 (or 25x25), export as byte[] and reload picture from this byte array ? 您想要的是调整大小166x166(或25x25),导出为byte []并从此字节数组重新加载图片吗?
Can you try with BitmapImage
? 您可以尝试使用
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.