Converting FileStream to WriteableBitmap to JPEG to Byte Array for SSRS

给你一囗甜甜゛ 提交于 2019-12-13 04:21:02

问题


I'm trying to save an Image to SQL Server so SSRS can read it. I need to convert to WriteableBitmap (and possibly JPEG?) so I can make changes to the image size before saving. However, when I try to pull the converted image out of SQL Server, it will not render in SSRS at all. 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;

回答1:


What you want is to resize 166x166 (or 25x25), export as byte[] and reload picture from this byte array ?

Can you try with 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();


来源:https://stackoverflow.com/questions/16529229/converting-filestream-to-writeablebitmap-to-jpeg-to-byte-array-for-ssrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!