Convert binary file to bitmap


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Convert binary file to bitmap

  1. #1
    Sara Guest

    Convert binary file to bitmap


    Hi,
    I have a VBprogram that accesses to SQL server to store all data.
    There is a field in vb where people can save pictures.
    I could convert that picture file to a binary file to save it to the database
    and it works all fine.
    Now, I am trying to pull out that binary file and convert it back to Picture
    file.
    I want to open the picture file with MSPAINT.
    I think I first have to save that binary as a bitmap file to a
    hard drive and open that file with a paint app.
    Does anybody know how to pull out that binary file from the database and
    save it as a bitmap in a hard drive?
    Thanks!

    Sara,




  2. #2
    Dennis Guest

    Re: Convert binary file to bitmap


    "Sara" <satokochan@hotmail.com> wrote:
    >
    >Hi,
    >I have a VBprogram that accesses to SQL server to store all data.
    >There is a field in vb where people can save pictures.
    >I could convert that picture file to a binary file to save it to the database
    >and it works all fine.
    >Now, I am trying to pull out that binary file and convert it back to Picture
    >file.
    >I want to open the picture file with MSPAINT.
    >I think I first have to save that binary as a bitmap file to a
    >hard drive and open that file with a paint app.
    >Does anybody know how to pull out that binary file from the database and
    >save it as a bitmap in a hard drive?
    >Thanks!
    >
    >Sara,
    >
    >
    >

    The following code assumes you are using MDAC 2.5, which is installed by
    VB6 SP4, SQL Server 2000 or Windows 2000. ADO 2.5 introduced the Stream.
    This function requires two arguments: an ADO recordset field that contains
    your binary data (the picture) and the name of the file you want saved, presumably
    with the file extension .bmp. I haven't used it with pictures, but it works
    fine with Word documents.

    Public Sub ColumnToFile(Col As ADODB.Field, sFile As String)
    Dim bstream As ADODB.Stream

    Set bstream = New ADODB.Stream
    bstream.Type = adTypeBinary
    bstream.Open
    bstream.Write Col.Value
    bstream.SaveToFile sFile, adSaveCreateOverWrite
    End Sub

    Dennis

  3. #3
    Sara Guest

    Re: Convert binary file to bitmap


    "Dennis" <DennisRehm@AppliedComputing.net> wrote:

    >The following code assumes you are using MDAC 2.5, which is installed by
    >VB6 SP4, SQL Server 2000 or Windows 2000. ADO 2.5 introduced the Stream.
    >This function requires two arguments: an ADO recordset field that contains
    >your binary data (the picture) and the name of the file you want saved,

    presumably
    >with the file extension .bmp. I haven't used it with pictures, but it works
    >fine with Word documents.
    >
    >Public Sub ColumnToFile(Col As ADODB.Field, sFile As String)
    > Dim bstream As ADODB.Stream
    >
    > Set bstream = New ADODB.Stream
    > bstream.Type = adTypeBinary
    > bstream.Open
    > bstream.Write Col.Value
    > bstream.SaveToFile sFile, adSaveCreateOverWrite
    >End Sub
    >
    >Dennis


    Thanks for your help! It worked great with pictures!
    but it always tries to save where the original file
    was located.
    Let's say, I have a picture on my desktop and I save
    that picture to my db. I delete that picture file from the
    desktop and when I ran my program, it saves my picture to
    the desktop. I think it's probably because of adSaveCreate
    OverWrite, right?
    I tried to use adSaveCreateNotExist to save the file
    to somewhere else, but it gave me a "Write to file failed"
    error (3004).
    I guess what I want to do is when I install my program
    to user's machine, I want to save that file to
    C:WINNT\Temp (assuming they all use Win 2000), so when
    they click the picture file name from a combo box,
    it will always read the file from the temp and open
    it with MSPAINT.
    Sorry to bother you a lot...
    I'm a very beginner programmer and don't quite understand
    how I can make this work.
    If you have any ideas how this can be done, please let
    me know!
    Thanks a lot!

    Sara


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center