-
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,
-
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
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks