vb.net 基于VB.NET中的byte()创建文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2549888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:48:30  来源:igfitidea点击:

Creating a file based on the byte() in VB.NET

vb.net

提问by acadia

I am retrieving an image from the SQL database into Byte() variable in VB.NET.

我正在将 SQL 数据库中的图像检索到 VB.NET 中的 Byte() 变量中。

Dim img as byte() = dr(0)

How do I create a file in my C:\images\ directory from the above img.

如何从上面的 img 在我的 C:\images\ 目录中创建一个文件。

I want to read the img and then create a file with name bimage.gif.

我想读取 img 然后创建一个名为 bimage.gif 的文件。

回答by Samuel Neff

The easiest way is to use File.WriteAllBytes

最简单的方法是使用 File.WriteAllBytes

Dim img as byte()=dr(0)
File.WriteAllBytes("C:/images/whatever.gif", img)

回答by MusiGenesis

System.IO.File.WriteAllBytes(@"c:\whatever.txt", bytes)

回答by Steve Danner

Try:

尝试:

Dim ms as MemoryStream = New MemoryStream(img)
Dim bmp as Bitmap = CType(Bitmap.FromStream(ms), Bitmap)

bmp.Save(@"C:\images\name.gif", ImageFormat.Gif);

bmp.Dispose()
ms.Dispose()