本文介绍了我无法在图片框中获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个程序,在该程序中我必须浏览并保存图像.一切都很好,但是在运行程序时,我无法将图像保存在图片框中,但我无法保存它.错误发生在"@imagedata"中.
这是我的代码...请帮助我.......
- - - - - - - - - - - -代码 - - - - - - - - - - - - - ------
I am working on a program where i have to browse and save the image. everything is going fine but while running the program i dint get the image in the picturebox and i am not able to save it. the error occurred in "@imagedata".
here''s my code...plz assist me.......
-----------------------CODE--------------------------------
Imports System
Imports System.Net
Imports System.Drawing
Imports System.Collections
Imports System.Componentmodel
Imports System.windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Data.SqlClient
Imports System.IO.Directory
Imports System.Threading
Public Class scan_salary
Dim con As New SqlConnection(str)
Private Sub btn_browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_browse.Click
Try
OFD1.Filter = "Jpg Files(*.Jpg)|*.Jpg" & "|Jpeg Files(*.Jpeg)|*.Jpeg" & "|Gif Files(*.Gif)|*.Gif"
If OFD1.ShowDialog = Windows.Forms.DialogResult.OK Then
Label4.Text = OFD1.FileName
Else
Label4.Text = ""
End If
If Label4.Text = "" Then
PictureBox1.Visible = False
Else
lbl_path.Text = Label4.Text
Dim imgdata() As Byte = readfile(lbl_path.Text)
Dim ms As MemoryStream = New MemoryStream(imgdata, 0, imgdata.Length)
ms.Write(imgdata, 0, imgdata.Length)
Dim img As Image = Image.FromStream(ms, True)
PictureBox1.Image = img
End If
'PictureBox1.Image = Image.FromFile()
lbl_path.Text = Label4.Text
Label4.Text = Label4.Text.Remove(Label4.Text.LastIndexOf("\"))
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
Public Function readfile(ByVal FPath As String) As Byte()
Dim data() As Byte
Try
Dim FI As New FileInfo(FPath)
Dim numbytes As Long = FI.Length
Dim fstream As FileStream = New FileStream(FPath, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fstream)
data = br.ReadBytes(Convert.ToInt64(numbytes))
fstream.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
Return data
End Function
Private Sub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click
If con.State <> ConnectionState.Open Then
con.Open()
Dim insdate, effdate As String
insdate = Now().Date
effdate = dtp1.Value.ToString
Dim emp_id As String = Class2.Empid
Dim sal As String = Class2.salary
Dim imgdata() As Byte = readfile(lbl_path.Text)
Dim cmd As New SqlCommand("insert into emp.dbo.scan_salary ( emp_id,salary, imagedata, insert_date, effect_date)" & _
"values ( '" & emp_id & "', '" & sal & "', '" & insdate & "','" & effdate & "',@imagedata", con)
cmd.Parameters.Add(New SqlParameter("@imagedata", CType(imgdata, Object)))
'cmd.Parameters.Add(New SqlParameter("@insert_date", DateTime.Now.ToString("yyyy-MM-dd")))
'cmd.Parameters.Add(New SqlParameter("@effect_date", dtp1.Value.ToString("yyyy-MM-dd")))
'cmd.Parameters.Add(New SqlParameter("@emp_id", emp_id.ToString))
'cmd.Parameters.Add(New SqlParameter("@salary", sal.ToString.Trim))
'cmd1.Parameters.Add(New SqlParameter("@Docimage", CType(imgdata, Object)))
cmd.ExecuteNonQuery()
cmd.CommandTimeout = 0
End If
MsgBox("document uploaded")
End Sub
End Class
推荐答案
这篇关于我无法在图片框中获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!