检索图片框中的图片 [英] retrieving picture in picturebox

查看:78
本文介绍了检索图片框中的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我在检索图片框中的图片时遇到问题

我有一个名为"DS"的数据集,并且在其中建立了memberPhotoTableAdapter.

我通过以下代码在窗体加载中调用MemberPhotoTableAdapter:

Me.MembersPhotoTableAdapter.FillBy(Me.DS.MembersPhoto,NationalCode.ToString())

这是在数据库中插入图片的代码:


hi
i have problem in retrieving picture in picturebox

i have a dataset named "DS" and i have built memberPhotoTableAdapter in it.

i call the MemberPhotoTableAdapter in form load by this code:

Me.MembersPhotoTableAdapter.FillBy(Me.DS.MembersPhoto, NationalCode.ToString())

this is the codes to insert picture in database :


Private Sub btnSavePic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSvePic.Click

        Try
            Dim ms As New MemoryStream()
            Photo.Image.Save(ms, Photo.Image.RawFormat)
            Dim arrPic As Byte() = ms.GetBuffer()
            ms.Close()
            MembersPhotoTableAdapter.InsertQuery(arrPic, NationalCode.ToString())
            MsgBox("pic saved")

        Catch ex As Exception
            MsgBox("Error")
        End Try
    End Sub

此代码效果很好,但是在检索图片时我遇到了问题.

这是在form_Load中检索图片的代码:

this code works well,but for retrieving the picture i have problem.

this is the code for retrieving picture in form_Load:

Dim arrPic As Byte()
       arrPic = DirectCast(DS.Tables("MembersPhoto").Rows(0)("pic"),Byte())
       Dim ms As MemoryStream = New MemoryStream(arrPic)
       Photo.Image = New Bitmap(ms)



我知道粗体线是错误的,并且在运行时显示错误,对于我之前为他们插入图片的人来说,显示此错误:

错误:参数无效

对于没有图片的人显示此错误:
错误:位置0没有行.

但是我写的舒尔德对此充满了兴趣



谢谢alot



i know that the bold line is wrong and in running time shows error, for the persons that i have inserted picture for them before, shows this error:

error: the parameter is not valid

and for the persons without picture showes this error:
error : there is no row in position 0.

but what shuold i write insted of that



thanks alot

推荐答案

最可能的原因是问题不是出在数据库上,而是在数据库中:
The most likely reason is that the problem is not with the reading out of the database, but with the saving into the database:
Photo.Image.Save(ms, Photo.Image.RawFormat)

尝试将其更改为

Try changing it to

Photo.Image.Save(ms, ImageFormat.Jpeg)


这篇关于检索图片框中的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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