CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Invalid Picture

  1. #1
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Invalid Picture

    I'm using this code to create an image file from the data in SQL Server:
    Dim RS As ADODB.Recordset
    Dim mstream As ADODB.Stream
    Set RS = New ADODB.Recordset
    RS.Open "Select HighLogo from CompanyData WHere CompanyID = " & lngCompanyID, objConn, adOpenKeyset, adLockOptimistic

    Set mstream = New ADODB.Stream
    mstream.Type = adTypeBinary
    mstream.Open
    mstream.Write RS.Fields("HighLogo").Value

    mstream.SaveToFile "c:\publogo.bmp", adSaveCreateOverWrite
    Picture1.Picture=LoadPicture("c:\publogo.bmp")
    I get an error "Invalid Picture"

    File is created, but I cannot open it with Paint or Photoshop.
    I link to the table in SQL Server from Access (I don't know any other way to see the picture in SQL Server field) and I can see the image there. So, SQL Server contains an image.
    I tried to insert different format images into the table (BMP, JPG, GIF). All of them I can see via Access.
    But when I retrieve the image and save as a disk file (tried with different extentions too), the file cannot be opened.

    What's wrong?
    Thank you

  2. #2
    Join Date
    Oct 2006
    Posts
    327

    Re: Invalid Picture

    But when I retrieve the image and save as a disk file (tried with different extentions too), the file cannot be opened.
    May we know how you do it ?
    More precisely :

    Do you save directly from the table data ?
    or :
    Do you save from a picturebox ?

  3. #3
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Invalid Picture

    The obvious error i see there is that your image is been stored as raw data (No header/Signature to id the type).
    Try to load the image from the DB direct to the Image box then to save as a BMP from the image box.
    Code:
    mstream.Type = adTypeBinary
    mstream.Write RS.Fields("HighLogo").Value
    mstream.SaveToFile "c:\publogo.bmp", adSaveCreateOverWrite
    this simply saves the raw image data : V-size, H-size, Pallete, Image data.
    Where a BMP needs a signature namely "BM6" to id it..

    use something like
    Code:
    SavePicture Picture1, "TEST.BMP"
    --- or ---
    SavePicture RS.Fields("HighLogo").Value "TEST.BMP"
    should give you a useable image file.

    Hope this helps...

    Gremmy.
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

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