如何将字节[]转换为图像 [英] how to convert byte [] to image

查看:146
本文介绍了如何将字节[]转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助找到此代码段中的错误:

byte[] a = objstud.viewtudentphoto(txtadminno.Text);
System.IO.MemoryStream ms = new System.IO.MemoryStream(a);
pictureBox2.Image = Image.FromStream(ms);



我在这里遇到错误:

pictureBox2.Image = Image.FromStream(ms);



这里objstud.viewtudentphoto(txtadminno.Text)返回图像
来自数据库

任何帮助将不胜感激.

谢谢.

解决方案

请看一下这篇出色的文章.假设您的方法objstud.viewtudentphoto(String txtImg)确实确实可以达到预期的效果,请查看CP上的这篇文章: ^ ].

希望对您有所帮助.

干杯!


,不知道objstud.viewtudentphoto的作用(我假设它从文件中加载图像),我只能假设它返回的图像严重转换为字节数组. /blockquote>

正如原始格里夫所说,不确定字节数组中有什么.如果您没有调整尺寸或代码更改了任何其他标头参数,则字节数组必须具有文件中的所有字节.不只是像素值.


I need help locating the error in this code snippet:

byte[] a = objstud.viewtudentphoto(txtadminno.Text);
System.IO.MemoryStream ms = new System.IO.MemoryStream(a);
pictureBox2.Image = Image.FromStream(ms);



I am getting the error here:

pictureBox2.Image = Image.FromStream(ms);



here objstud.viewtudentphoto(txtadminno.Text) returns an image
from database

Any help is greatly appreciated.

Thanks.

解决方案

Please have a look at this excellent article. Taking it as a given that your method objstud.viewtudentphoto(String txtImg) does indeed do what you expect of it please take a look at this article on CP: C# Image to Byte Array and Byte Array to Image Converter Class[^].

Hope this helps some.

Cheers!


Without knowing what objstud.viewtudentphoto does (I assume it loads an image from a file) I can only assume that it returns an image that is badly converted to a byte array.


As Original Griff said it is not sure what is there in the byte array. The byte array has to have all the bytes from the file as such if you haven''t re dimension or any other header parameters changed by your code. Not just the pixel values.


这篇关于如何将字节[]转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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