locked
uploading image to database help please. RRS feed

  • Question

  • User-1615261397 posted
    I seem to be having problems getting a photo from a users computer and converting it to an image so I can use GDI functions and then back to a stream so that I can store it into a database.  Here is the code I have - I don't get any errors when running it, but the image is never usable.

    if(pic.PostedFile != null)
                                {
                                    string picType = pic.PostedFile.ContentType.ToString();
                                    int picSize = pic.PostedFile.ContentLength;
                               
                                    System.Drawing.Image picTemp = System.Drawing.Image.FromStream(pic.PostedFile.InputStream);
                                   
                                    System.Drawing.Image imgPhototemp = FixedSize(picTemp, 200, 250);
                                   
                                    MemoryStream picStream = new MemoryStream();

                                    imgPhototemp.Save(picStream,System.Drawing.Imaging.ImageFormat.Jpeg);

                                    int picLength = (int)picStream.Length;
                                    byte[] picBuffer = new byte[picLength];
                                       
                                    picStream.Read(picBuffer,0,picLength);
                           
                                    addRow.Pic = picBuffer;
                                }


    Any help would be greatly appreciated.  Thanks!  
    Friday, March 3, 2006 9:02 PM

All replies

  • User-151304380 posted

    I seem to be having problems getting a photo from a users computer and converting it to an image so I can use GDI functions and then back to a stream so that I can store it into a database.  Here is the code I have - I don't get any errors when running it, but the image is never usable.

    if(pic.PostedFile != null)
                                {
                                    string picType = pic.PostedFile.ContentType.ToString();
                                    int picSize = pic.PostedFile.ContentLength;
                               
                                    System.Drawing.Image picTemp = System.Drawing.Image.FromStream(pic.PostedFile.InputStream);
                                   
                                    System.Drawing.Image imgPhototemp = FixedSize(picTemp, 200, 250);
                                   
                                    MemoryStream picStream = new MemoryStream();

                                    imgPhototemp.Save(picStream,System.Drawing.Imaging.ImageFormat.Jpeg);

                                    int picLength = (int)picStream.Length;
                                    byte[] picBuffer = new byte[picLength];
                                       
                                    picStream.Read(picBuffer,0,picLength);
                           
                                    addRow.Pic = picBuffer;
                                }


    Any help would be greatly appreciated.  Thanks!  

    Hi aaj23,

    I am trying to upload pics to an image field of my database as well. Have you found a solution to your issue above? Thanks.

    blumonde

    Tuesday, September 5, 2006 6:47 PM