[英]Converting FileStream to WriteableBitmap to JPEG to Byte Array for SSRS
[英]FileStream (jpeg from pdf converter) to Byte[]
使用aspose,我已经将pdf文档的第一页转换为jpeg(将在“文档”部分的缩略图用作我的asp.net页之一)。 到目前为止,这已存储在FileStream中-但我需要一个字节数组来分配给Image控件的datavalue。 谁能指出我正确的方向以进行转换? 我环顾四周,找不到解决方案。
非常感谢。
这应该工作:
byte[] data = File.ReadAllBytes("path/to/file.jpg")
var memStream = new MemoryStream();
yourFileStream.CopyTo(memStream);
var bytes = memStream.ToArray();
你可以试试这个。
/// <summary>
/// Function to get byte array from a file
/// </summary>
/// <param name="_FileName">File name to get byte array</param>
/// <returns>Byte Array</returns>
public byte[] FileToByteArray(string _FileName)
{
byte[] _Buffer = null;
try
{
// Open file for reading
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
// attach filestream to binary reader
System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);
// get total byte length of the file
long _TotalBytes = new System.IO.FileInfo(_FileName).Length;
// read entire file into buffer
_Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes);
// close file reader
_FileStream.Close();
_FileStream.Dispose();
_BinaryReader.Close();
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
}
return _Buffer;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.