|
Subject:
|
Passing Image File as a parameter
|
|
Posted By:
|
MAKO
|
Post Date:
|
10/6/2006 2:33:26 PM
|
Hello Professionals of this forum! I need to code a program for a server client employee record application in windows with C#. I need to learn first, how can I fill a control like a picture box on the windows form from a picture file saved on de PC, and second, how can I initialize some type of variable in code to pass that same picture as a parameter to the stored procedure that inserts each record for the employees table in my DB? Please help is greatly appreciated and needed, I'm new to C#, I'm learning, but my boss want's me to fullfil this task with no excuses. Thanks a lot in advance!
Greetings,
MAKO - "El super simio"
|
|
Reply By:
|
bijgupt
|
Reply Date:
|
10/7/2006 4:04:17 AM
|
Use System.Drowing.Image. To store image in db declare field type as image->> http://p2p.wrox.com/topic.asp?TOPIC_ID=50608
Bijgupt
|
|
Reply By:
|
MAKO
|
Reply Date:
|
10/10/2006 12:24:10 PM
|
Thanks for your reply Bijgupt, it is a guiding light. However I'm still not quite clear of how can I initialize the image variable with the picture file stored in the disc. I thought of an open file dialog for the user to search for the file, but then I get confused with how to do the rest to initialize the image variable. A little bittie more help, please! Thank you!
MAKO - "El super simio"
|
|
Reply By:
|
dparsons
|
Reply Date:
|
10/10/2006 12:55:49 PM
|
What you can do is, for example, place a picture box on your form with a default image then use your File Dialog and have the user select an image file. Now here is the question I have, after the use selects the image from the file dialog does that image need to be automatically placed in the picture box?
Or, after the user selects a file, do they hit submit of some sort to write the image to a database THEN the picture box has an image associated with it?
If you look at the code for your form and, assume that you have added an image to the picturebox your code will look something like:
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("picture.ext")));
All its doing is casting the object to a type of System.Drawing.Image.
If, for example, you were to stream this file to disk as opposed to saving it to the database you could do something like this in code:
pictureBox1.Image = Image.FromFile("pic.jpg")
However, since you need to place this into a database you are going to have to write some GDI functionality that will pull the byte stream from SQL and then create an image object on the fly. (Depending on your skill set, GDI can be a bit of a challenge, but for what you need to do, it is relatively simplistic)
For example: Bitmap bmpFile; MemoryStream stmFile = new MemoryStream(); BinaryWriter objWriter = new BinaryWriter(stmFile); objWriter.Write(dtImg.Rows[0][0]); bmpFile = new Bitmap(stmFile);
I assume you pull back the data into a datatable and that the data sits at Row 0 Position 0
From there all you have to do is add it to your picture box.
hth
--Stole this from a moderator
I will only tell you how to do it, not do it for you. Unless, of course, you want to hire me to do work for you.
|