Click here to Skip to main content
16,022,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a scanning device which makes me can capture an image and store it into picture box without reading from hard disk, i want to be able to insert the image into database directly from the picturebox without reading it from a specified path
any sample of code ?

Thanks
Posted

1 solution

C#
private static void SavePictureBoxToDatabase(PictureBox myPictureBox)
    {
    MemoryStream ms = new MemoryStream();
    myPictureBox.Image.Save(ms, ImageFormat.Jpeg);
    ms.Seek(0, 0);
    WriteToMyDatabase(ms.GetBuffer());
    }
Obviously, you have to write the WriteToMyDatabase method since we don't know what database type you are dealing with...
 
Share this answer
 
Comments
snake1 3-Aug-11 9:59am    
myPictureBox.Image.Save(ms,ImageFormat.Jpeg)

i get an exception here object reference not set
OriginalGriff 3-Aug-11 10:03am    
Did you pass it a PictureBox? If so, did you set the Image first? You did say that your scanner stores it to a PictureBox and the Image is the only relevant property...
snake1 3-Aug-11 10:22am    
i have scanned the image and i get this error
the picturebox image is null while setting breakpoint
btw i'm using sqldatabase
OriginalGriff 3-Aug-11 10:24am    
Then your scanner did not put the image into the picture box as you think it did.
You need to look at the scanner documentation, or rethink the way you are controlling it. What are you actually doing to scan the image?
snake1 3-Aug-11 10:36am    
what if i set the specified image at the designer,why is the picturebox.image in this case is null too?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900