繁体   English   中英

将FileStream转换为WriteableBitmap,将JPEG转换为SSRS的字节数组

[英]Converting FileStream to WriteableBitmap to JPEG to Byte Array for SSRS

我正在尝试将图像保存到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;

您想要的是调整大小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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM