Posts: 159
Threads: 25
Joined: Mar 2012
Reputation:
0
Can you be more specific? I don't understand what do you mean.
Also known as Rocketalypse.
System.out.println("I prefer Java.");
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
I don't really know what you mean either. To display a picture in your program, you're going to want to use the PictureBox control, but that's all the help that I can really give you with the information that you provided.
Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
oh.. im sorry.. lets say i have a database table name student_info. one of the fields i created is the imagepath.. i want to save the path of the image in that field.. and after saving that if i want to view the student info in my program..the student info appears and so as the image.. how can i do that?
Posts: 159
Threads: 25
Joined: Mar 2012
Reputation:
0
I'm going to sleep right now, meaning I don't have time to help, at the moment. If Brandon doesn't help you in a few hours, when I wake up I will.
Right now, it is like 0:50 am here, so yeah. I usually wake up at 08:00/08:30(am).
Also known as Rocketalypse.
System.out.println("I prefer Java.");
Posts: 159
Threads: 25
Joined: Mar 2012
Reputation:
0
What you could do is use this code when you click buttons for scrolling (Next, Previous, First, Last):
[code2=vbnet]Try
PictureBox1.Image = Image.FromFile(ImageTextBox.Text)
Catch ex As Exception
MsgBox(ex.Message) ' Style your message box a bit, if you want.
End Try[/code2]
When an user clicks the upload button, add this code:
[code2=vbnet]Dim OpenImage As New OpenFileDialog
OpenImage.Title = "Upload your image"
OpenImage.InitialDirectory = "C:\"
OpenImage.Filter = "Images Files|*.jpg;*.png;*.jpeg;*.bmp"
Dim x = OpenImage.ShowDialog()
If x = DialogResult.OK Then
Try
PictureBox1.Image = Image.FromFile(OpenImage.FileName)
ImageTextBox.Text = OpenImage.FileName
Catch ex As Exception
MsgBox(ex.Message) ' Style your message box a bit, if you want.
End Try
End If[/code2]
That is basically it. That's everything you need in order to display an image. If you want to display .GIF images, you need to use StreamWriter, otherwise it will say "Out of Memory". When the form loads, it doesn't matter which file extension the image have, it will show "Out of Memory", so don't add it there. Everything else works like a charm. If this didn't help you totally, it at least gave you some kind of idea how would it work.
Also known as Rocketalypse.
System.out.println("I prefer Java.");
Posts: 159
Threads: 25
Joined: Mar 2012
Reputation:
0
Are you using MySQL database or Service-Based (in VB/VS) database?
Also known as Rocketalypse.
System.out.println("I prefer Java.");
Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
yea i'm using MySQL database..
Posts: 159
Threads: 25
Joined: Mar 2012
Reputation:
0
I cannot help you then. I've never used MySQL databases. Brandon will help you when he logs on.
Basically what you want to do is, retrieve a value from the path column and then set PictureBox's image to it.
Also known as Rocketalypse.
System.out.println("I prefer Java.");
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
Thanks for helping Vinwarez!
Anyway, there is a very basic premise to what you are trying to do. Basically, user chooses image, image gets uploaded, URL of that image gets saved in the database.
So, for example, if you specify a local image for the student "John Smith", the image might get renamed as "johnsmith81212.jpg" and then uploaded via FTP to the url "site.com/images/johnsmith81212.jpg". Then, the MySQL image field for "John Smith" is updated to "johnsmith81212.jpg". Then, when retrieving the image, the program reads the MySQL field, downloads the image, and displays it into the PictureBox.
This may not be the best way of doing it, but it is how I did it in a huge piece of software for a client and it seemed to get the job done.
Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
no.. what if the images i uploaded is on the local folder only..? like inside the image folder i created inside the debug folder? how can i save the image path to the database and retrieve it to the database to show it in picture box? so how am i gonna do that? can you show me some example please to better understand?
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
If they are on the local folder only, then simply save a MySQL Field containing the file name for each student, then load that picture!
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
Which part do you need help coding? The MySQL part? The reading pictures from a file part?
Posts: 18
Threads: 4
Joined: Aug 2012
Reputation:
0
reading pictures from a file path..
Posts: 1,006
Threads: 111
Joined: Jul 2010
Reputation:
1
Ah, well this should help you out! This code loads a picture from the filesystem and loads it into a picturebox!
[code2=vbnet]Dim picture As Image = _
Image.FromFile(My.Application.Info.DirectoryPath & "/images/picture.png")
PictureBox1.Image = picture[/code2]