Save Image to Database from Picturebox 
Author Message
 Save Image to Database from Picturebox

Hi Cynthia,

I have the exact same problem and I am not even converting the icon to JPEG.
I store the icon directly to the database and still it has lost its
transparency when I load it again. It doesn't seem to matter if you show it
in a picturebox or in a ListView-control (via an ImageList), it still gets
black.

The same problem occured many times for me in VB6 too, so maybe it has
something to do with how Windows handles icons, I am not sure...I really
need to know how to solve this one too. Anyone?

/Per Hultqvist


Quote:

>    Help !

>    I am placing an Icon onto my picture box from a
> openFileDialog box selection.
>    Once I have the icon on my pictureBox I am converting
> it to JPEG and storing it into a memory stream like this:
> picIcon.Image.Save
> (ms,System.Drawing.Imaging.ImageFormat.Jpeg)
> I then read it in:
> objMS.Read(bytIcon, 0, objMS.Length)
> ''btyIcon is my byte array.

> Next I save it to the database.  Everything works fine
> except;  my problem is when retrieving it the background
> of the picture on the picture box is black. WHY?
> I load it back onto my pictureBox with the following code:
>  '   set up memory stream
>  MS = New MemoryStream(bytIcons)
> '   place image into picture box
>  picIcon.Image = Image.FromStream(MS)
> '   close stream object
>  objMS.Close()

> I think the problem is in the convertion of icon to JPEG
> format, but I don't know how to fix this.  The picture is
> fine, but the background color is black.
> Somebody please help
> Thanks
> Cynthia



Wed, 18 May 2005 03:29:35 GMT  
 Save Image to Database from Picturebox
How does that help if I suggest you to add in the transparency information
back to the image (jpeg) or icon after you retrieve it from database?
Code to add transparency to a bitmap is:

' assuming that you have a bitmap object called myBitmap
' dim myBitmap as bitmap = ' retrieve the bitmap from db

myBitmap.makeTransparent(color.black)
picturebox1.image = myBitmap

Hope that helps.
-M-


Quote:
> Hi Cynthia,

> I have the exact same problem and I am not even converting the icon to
JPEG.
> I store the icon directly to the database and still it has lost its
> transparency when I load it again. It doesn't seem to matter if you show
it
> in a picturebox or in a ListView-control (via an ImageList), it still gets
> black.

> The same problem occured many times for me in VB6 too, so maybe it has
> something to do with how Windows handles icons, I am not sure...I really
> need to know how to solve this one too. Anyone?

> /Per Hultqvist



> >    Help !

> >    I am placing an Icon onto my picture box from a
> > openFileDialog box selection.
> >    Once I have the icon on my pictureBox I am converting
> > it to JPEG and storing it into a memory stream like this:
> > picIcon.Image.Save
> > (ms,System.Drawing.Imaging.ImageFormat.Jpeg)
> > I then read it in:
> > objMS.Read(bytIcon, 0, objMS.Length)
> > ''btyIcon is my byte array.

> > Next I save it to the database.  Everything works fine
> > except;  my problem is when retrieving it the background
> > of the picture on the picture box is black. WHY?
> > I load it back onto my pictureBox with the following code:
> >  '   set up memory stream
> >  MS = New MemoryStream(bytIcons)
> > '   place image into picture box
> >  picIcon.Image = Image.FromStream(MS)
> > '   close stream object
> >  objMS.Close()

> > I think the problem is in the convertion of icon to JPEG
> > format, but I don't know how to fix this.  The picture is
> > fine, but the background color is black.
> > Somebody please help
> > Thanks
> > Cynthia



Thu, 19 May 2005 14:25:36 GMT  
 Save Image to Database from Picturebox
I use the two functions below to save and retrieve images from a
sql database.

check them out

Francisco Mejia

 Code
======
Public  Function GetImageById(ByVal RowId As Integer) As Image
Dim s As String = "Select Picture from PersonPicture where RowId = " & RowId
Dim r As SqlClient.SqlDataReader = GetReader(s)
If r.Read Then
Dim lg As Long = r.GetBytes(0, 0, Nothing, 0, 10000)
Dim picdata(Integer.Parse(lg.ToString)) As Byte
Dim bytBLOBData(r.GetBytes(0, 0, Nothing, 0, Integer.MaxValue - 1) - 1) As
Byte
r.GetBytes(0, 0, bytBLOBData, 0, bytBLOBData.Length)
Dim stmBLOBData As New MemoryStream(bytBLOBData)
Return Image.FromStream(stmBLOBData)
End If
End Function

Public  Sub SavePictureFromFileSQL(ByVal FilePath As String, ByVal
SourceFilePath As String, ByVal PersonId As Integer, ByVal Description As
String)
Dim cn As New SqlConnection(ConnectionString)
Dim cmd As New SqlCommand("insert into PersonPicture

cn)
Dim P As SqlParameter
Try
'read the file
Dim fs As New System.IO.FileStream(FilePath, IO.FileMode.Open,
IO.FileAccess.Read)
Dim iLength As Long = fs.Length
Dim b(CType(iLength, Integer) - 1) As Byte
fs.Read(b, 0, b.Length)
fs.Close()

cmd.Parameters.Add(P)

cmd.Parameters.Add(P)

cmd.Parameters.Add(P)

ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, b)
cmd.Parameters.Add(P)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
Catch x As Exception
MsgBox(x.Message)
End Try
End Sub



Sat, 04 Jun 2005 06:52:05 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help!! Loading PictureBox FromStream and PictureBox.Image.Save

2. ADVANCED: Saving Picturebox-image as GIF

3. Save An Appended Image file loaded in the PictureBox

4. How to save a Picturebox Image

5. Save an image using PictureBox control?

6. Saving an image in a picturebox.

7. Saving the image in an Picturebox to something other then a BMP

8. Save An Appended Image file loaded in the PictureBox

9. ADVANCED: Saving Picturebox-image as GIF

10. picturebox /container save image

11. Save an image using PictureBox control?

12. Saving Image or PictureBox control's contents to file (BMP/JPG etc)

 

 
Powered by phpBB® Forum Software