将字节转换为图像 [英] convert byte to image
问题描述
你好朋友的
我的图片中有二进制形式的数据库.
我只有一种形式,只有一个班级
在班级中有sqlconnection,形式没有
我想通过这种方式传递给第二种形式:public byte [] imege {get;放; }
请告诉我该怎么做?
Hello Friend''s
I have database in binary form in picture.
i have one form and one class
in class have sqlconnection and form have not
i want to pass using like this to second form : public byte[] imege { get; set; }
plz tell me how to i do this?
推荐答案
您有Byte []( byteArray )吗?
将字节直接写入文件
Do you have Byte[] (byteArray) ?
Write the byte to file directly
System.IO.File.WriteAllBytes("C:\Text.jpg"); //Replace your Filepath
如果将byte
转换为图像,它将是非常小的图像. :-)
您确实是在问一个字节数组.方法是:将字节放入内存流中,然后使用System.Drawing.Image.FromStream
读取此内存流.
If you convert abyte
to an image, it will be really small image. :-)
You really are asking about an array of bytes. Here is the way: you put the bytes in a memory stream and read this memory stream withSystem.Drawing.Image.FromStream
.
byte[] imageData = //...;
//...
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(imageData)) {
System.Drawing.Image image = new System.Drawing.Image.FromStream(stream);
} // stream dispose is called here implicitly
参见:
http://msdn.microsoft.com/en-us/library/system. drawing.image.fromstream.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.io. memorystream.aspx [ ^ ].
如果需要,WPF也可以使用类似的方法.请参见,例如: http://forums.silverlight.net/p/44637/121951.aspx [< ^ ].
See:
http://msdn.microsoft.com/en-us/library/system.drawing.image.fromstream.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx[^].
If you want, WPF has similar methods. Please see, for example: http://forums.silverlight.net/p/44637/121951.aspx[^].
这篇关于将字节转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!