字节数组到图像的解决方案 [英] solution for byte array to image

查看:86
本文介绍了字节数组到图像的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:





The code is given below,


var html = String.Format("<body>Hello world: {0}</body>", DateTime.Now);
            var htmlToImageConv = new NReco.ImageGenerator.HtmlToImageConverter();
            var jpegBytes = htmlToImageConv.GenerateImage(html, ImageFormat.Jpeg);







在上面的代码中,jpegBytes包含如何将字节数组转换为图像的字节数组







请帮帮我...

先谢谢




In the above code jpegBytes contains the byte array how to convert the byte array to image



pls help me...
Thanks in Advance

推荐答案

保存字节数组到文件

File.WriteAllBytes(字符串路径,字节[]字节)

我认为这应该有帮助。如果不是,请解释一下你的困难。
Save byte array to file
File.WriteAllBytes(string path, byte[] bytes)
I think this should help. If no, please explain a little bit more about your difficulties.


ImageGenerator返回JPEG图像的字节数组。

你可以将它加载到Image对象中以下代码:



var img = Image.FromStream(new MemoryStream(jpegBytes));

Console.WriteLine(Image size:{ 0} x {1},img.Width,img.Height);
ImageGenerator returns bytes array of the JPEG image.
You can load it into Image object with the following code:

var img = Image.FromStream( new MemoryStream(jpegBytes) );
Console.WriteLine("Image size: {0}x{1}", img.Width, img.Height);


public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
     MemoryStream ms = new MemoryStream();
     imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
     return  ms.ToArray();
}




public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}



阅读此CodeProject文章: C#映像到字节数组和字节数组到映像转换器类 [ ^ ]



-KR


Read this CodeProject article: C# Image to Byte Array and Byte Array to Image Converter Class[^]

-KR


这篇关于字节数组到图像的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆