הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Wednesday, December 5, 2012 4:50 PM
Hi all,
I would like to convert a string in an image.
For example, I have a string that contains a path to an image and I'd like to insert that image in a PictureBox, so I need to convert it to a System.Drawing.Image.
I've tried to follow the forum solution at: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/00da653f-7291-42c0-a0e7-34f4ce1a85b4/ but Visual Studio get me a lot of errors and I can't find the namespace System.Windows.Media.Imaging (maybe it's only for WPF?).
Please help me
Panda
All replies (6)
Wednesday, December 5, 2012 5:47 PM ✅Answered
Here's another way of doing it from a file
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Load("C:\Users\John\Desktop\Test1.png")
Dim bitmap As New Bitmap("C:\Users\John\Desktop\Picture Files\Crossbones BMP.Bmp")
ToolStripButton2.Image = CType(bitmap, System.Drawing.Image)
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
Private Sub ToolStrip1_ItemClicked(sender As Object, e As ToolStripItemClickedEventArgs) Handles ToolStrip1.ItemClicked
End Sub
End Class
You've taught me everything I know but not everything you know.
Wednesday, December 5, 2012 5:03 PM
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Load("C:\Users\John\Desktop\Test1.png")
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
End Class
You've taught me everything I know but not everything you know.
Wednesday, December 5, 2012 5:10 PM
Thank you!
But if I would like to set the image in the "Image" property of a ToolstripButton?
Panda
Wednesday, December 5, 2012 5:23 PM
First add the image as a resource to your application then
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
PictureBox1.Load("C:\Users\John\Desktop\Test1.png")
ToolStripButton1.Image = My.Resources.Crossbones_BMP
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
Private Sub ToolStrip1_ItemClicked(sender As Object, e As ToolStripItemClickedEventArgs) Handles ToolStrip1.ItemClicked
End Sub
End Class
You've taught me everything I know but not everything you know.
Wednesday, December 5, 2012 5:41 PM
Thanks Mr.Monkeyboy, but that's not what I'm searching for, because I would like, if it's possible, to add the image to a ToolStripButton from the string that contains the filename.
Bye ;)
Wednesday, December 5, 2012 6:48 PM | 2 votes
The most simple one for a windows forms is is.
Picturebox1.Image = Image.FromFile("Path")
Success
Cor