将字节数据加载到图片框 [英] Loading byte data to a picture box

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

问题描述

我已使用以下代码将图像保存在数据库中.

I have saved an image in database using following code.

ofd.ShowDialog()
    vrPicHolder = IO.File.ReadAllBytes(ofd.FileName)
    Dim drPic As DataRow
    drPic = DsPic.tblPicTest.NewRow
    drPic.Item("Picture") = vrPicHolder
    DsPic.tblPicTest.Rows.Add(drPic)
    taPic.Update(DsPic.tblPicTest)

现在我想在图片框中显示此图像.我试过了

Now I want to display this image in a picture box. I tried

PictureBox1.Image = Image.FromFile(vrPicHolder)

但它说不能将 Byte() 转换为字符串.请告知如何加载此图片.谢谢弗坎

But it says can not convert Byte() to string. Please advise how to load this picture. Thanks Furqan

推荐答案

您正在调用的方法需要一个字符串,该字符串是图像的文件名.您需要将 BMP、GIF、JPEG、PNG 或 TIFF 格式的图像的文件名传递给它.

The method you're calling expects a string that's the filename of an image. You need to pass it the filename of an image that is a BMP, GIF, JPEG, PNG or TIFF format.

Image.FromFile 方法(字符串)

你应该做的是:

Dim pictureBytes as New MemoryStream(vrPicHolder)
PicutureBox1.Image = Image.FromStream(pictureBytes)

Image.FromStream 方法(流)

这篇关于将字节数据加载到图片框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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