将图像从我的源加载到图片框 [英] Load the Image from my source to picturebox

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

问题描述

亲爱的朋友们,



如果你必须挑战我们如何从Visual Basic 2012中的资源中加载图片框工具中的图像。例如,如果我点击图片框然后打开我的资源弹出菜单,我可以在其中选择我的图片并将其插入图片框。



如果你已经完成在你的练习过去然后给我代码。这有可能对你来说..... ??



我希望你为我的任务做好和努力工作。

< br $>


感谢你,



MP Patni

Dear Friends,

If you have to challenge that How can we load the image in picture box tools from the my resources in Visual Basic 2012. For Example, If I have click on picture box then open my resource pop up menu in which I can select my picture and insert it into the picture box.

If you had been done in past of your practice then give me the codes. Is this possible for you.....??

I hope you are good and hard working human for my task.


Thanking You,

M P Patni

推荐答案

请阅读规则:代码项目快速解答常见问题解答 [ ^ ]然后点击此链接:搜索图像和资源 [ ^ ]



下次请在提问之前使用搜索框,好吗?
Please, read the rules: Code Project Quick Answers FAQ[^] and then follow this link: Search for image and resource[^]

Next time, please use Search Box before you ask a question, OK?


试试这个...........





公共课堂表格

Dim ssavepath1 As String =\ photo



私有函数convertPicBoxImageToByte(ByVal pbImage As System.Windows.Forms.PictureBox)As Byte()

Dim ms As New System.IO.MemoryStream()

试试

pbImage.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg)

返回ms.ToArray()

Catch ex作为例外



结束尝试



结束功能



Private Sub browse_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理RadButton1.Click



尝试

OpenFileDialog1.Title =请选择图像

OpenFileDialog1.ShowDialog()



str1 = OpenFileDialog1.FileName()



Dim chk()As String = {.jpg,。gif,。jpeg,。png,。 ico}

Dim k As Integer = chk.Count

Dim i As Integer = 0

Dim i1 As Integer = 0

而(i< k)

If(System.IO.Path.GetExtension(OpenFileDialog1.FileName())。ToLower()= chk(i).ToString)然后

PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)



i1 = 1

退出时

结束如果

i = i + 1

结束时

如果(i1 = 1)那么



str1 = str1.Substring(str1.LastIndexOf(\))

Dim strFilePath As String = Application.StartupPath

Dim strFilePathstrFilePath As String = strFilePath.Substring( 0,strFilePath.LastIndexOf(\))

Dim strFilePathstrFilePath1 As String = strFilePathstrFilePath.Substring(0,strFilePathstrFilePath.LastIndexOf(\))&ssavepath1&str1

PictureBox1.Image.Save(strFilePathstrFilePath1)





Else

MsgBox(仅选择带.jpg,.gif,.jpeg,.png,.ico扩展名的图片)

结束如果

Catch ex As Exception



结束尝试



end sub





Private Sub btn_save_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles btn_save.Click







Dim b As Byte()= New Byte(-1){}



b = convertPicBoxImageToByte(PictureBox1)





Dim con As SqlConnection =新的SqlConnection(Module1.con)



Dim cmd As SqlCommand = New SqlCommand()

cmd.Connection = con





cmd.CommandText =(INSERT INTO Company_master(company_name,image)VALUES(@ a,@ b))

con.Open()

cmd.Parameters.AddWithValue(a,txt_com_nm.Text)

cmd.Parameters.AddWithValue(b,b)









Dim i As Integer = cmd.ExecuteNonQuery()



con.Close()



如果我<> 0然后

MsgBox(成功保存记录,MsgBoxStyle.Information)



fill()

' 'clear()

clear(Me)

PictureBox1.Image = Nothing



结束如果

结束如果

结束子



结束班
Try this...........


public class form
Dim ssavepath1 As String = "\photo"

Private Function convertPicBoxImageToByte(ByVal pbImage As System.Windows.Forms.PictureBox) As Byte()
Dim ms As New System.IO.MemoryStream()
Try
pbImage.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Return ms.ToArray()
Catch ex As Exception

End Try

End Function

Private Sub browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click

Try
OpenFileDialog1.Title = "Please Select Image"
OpenFileDialog1.ShowDialog()

str1 = OpenFileDialog1.FileName()

Dim chk() As String = {".jpg", ".gif", ".jpeg", ".png", ".ico"}
Dim k As Integer = chk.Count
Dim i As Integer = 0
Dim i1 As Integer = 0
While (i < k)
If (System.IO.Path.GetExtension(OpenFileDialog1.FileName()).ToLower() = chk(i).ToString) Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)

i1 = 1
Exit While
End If
i = i + 1
End While
If (i1 = 1) Then

str1 = str1.Substring(str1.LastIndexOf("\"))
Dim strFilePath As String = Application.StartupPath
Dim strFilePathstrFilePath As String = strFilePath.Substring(0, strFilePath.LastIndexOf("\"))
Dim strFilePathstrFilePath1 As String = strFilePathstrFilePath.Substring(0, strFilePathstrFilePath.LastIndexOf("\")) & ssavepath1 & str1
PictureBox1.Image.Save(strFilePathstrFilePath1)


Else
MsgBox("select image with .jpg, .gif, .jpeg, .png, .ico extention only")
End If
Catch ex As Exception

End Try

end sub


Private Sub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click



Dim b As Byte() = New Byte(-1) {}

b = convertPicBoxImageToByte(PictureBox1)


Dim con As SqlConnection = New SqlConnection(Module1.con)

Dim cmd As SqlCommand = New SqlCommand()
cmd.Connection = con


cmd.CommandText = ("INSERT INTO Company_master (company_name,image)VALUES (@a,@b)")
con.Open()
cmd.Parameters.AddWithValue("a", txt_com_nm.Text)
cmd.Parameters.AddWithValue("b", b)




Dim i As Integer = cmd.ExecuteNonQuery()

con.Close()

If i <> 0 Then
MsgBox("Record Saved Successfully", MsgBoxStyle.Information)

fill()
''clear()
clear(Me)
PictureBox1.Image = Nothing

End If
End If
End Sub

End Class


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

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