CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Posts
    2

    Image to to Stream of Byte[]?

    Image to to Stream of Byte[]?
    I have an image in the pictureBox captured from a device.Now i want to convert this PicBox.Image to stream of bytes to save it in the DataBase.Plz help me how to convert this image from pictureBox to stream of bytes.I
    pretty know how to save it in database but having some problem converting the image to stream of bytes from PictureBox.
    Thnx in Advance!

  2. #2
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: Image to to Stream of Byte[]?

    Save the Image to a MemoryStream.
    Useful? Then click on (Rate This Post) at the top of this post.

  3. #3
    Join Date
    Aug 2005
    Location
    Tamilnadu, India
    Posts
    4

    Re: Image to to Stream of Byte[]?

    define the parameter for those insert command so that the image get converted to the byte stream while entering into the database.

  4. #4
    Join Date
    Aug 2003
    Location
    London
    Posts
    515

    Re: Image to to Stream of Byte[]?

    This works for me...

    Save to byte array...
    Code:
    ImageConverter ic = new ImageConverter(); 
    byte[] imageBuffer  = (byte[]) ic.ConvertTo(MyImageVariable, typeof(byte[]));
    Call a method that takes the byte array for data update..
    Code:
    public bool SaveSignature(int userID, byte[] signature)
    {
    			DBCommandWrapper wrapper = _db.GetStoredProcCommandWrapper("CODBA.usr_UpdateSignature");
    			
    			wrapper.AddInParameter("@UserID", DbType.Int32, buyerID);
    			wrapper.AddInParameter("@Signature", DbType.Binary, signature);
    
    			try
    			{
    				_db.ExecuteNonQuery(wrapper);
    				return true;
    			}
    			catch
    			{
    				throw;
    			}			
    }
    Your stored procedure...
    Code:
    CREATE PROCEDURE  CODBA.usr_UpdateSignature
    
    	(
    		@UserID			SMALLINT, 
    		@Signature			IMAGE
    	)
    
    AS
    
    etc...normal database update now.
    If it helped, then please rate the post by clicking "Rate this post"!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured