473,322 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to write binary(bmp) data to a file?

kee
Hi All,

I am trying to write binary data to a file, which is bmp image:

Open "d:\temp\test001.bmp" For Binary Access Write As #1
Put #1, 1, strImage
Close #1

*** strImage contains binary data

when i try to open the bmp it show invalid bitmap file.

Appreciate if anyone can help.

Thanks

kee

Jul 17 '05 #1
3 15633
kee <ke***@kee.dynu.com> wrote in message news:<40**********@news.tm.net.my>...
Hi All,

I am trying to write binary data to a file, which is bmp image:

Open "d:\temp\test001.bmp" For Binary Access Write As #1
Put #1, 1, strImage
Close #1

*** strImage contains binary data

when i try to open the bmp it show invalid bitmap file.


a few thoughts...

Does the file exist already? If so it may be longer than what you
write.

You don't need the ", 1": Put #1,,strImage

Using strings for binary data is good for VB3 and earlier but starting
with VB4 you get ansi/unicode translations going on and that may be
affecting you. Use a byte array instead of a string for binary data.

How are you getting the data? My guess is that's where it is getting
corrupted.

BTW, you should use the FreeFile function rather than hard-coding #1
Jul 17 '05 #2
kee
Bob Butler wrote:
kee <ke***@kee.dynu.com> wrote in message news:<40**********@news.tm.net.my>...
Hi All,

I am trying to write binary data to a file, which is bmp image:

Open "d:\temp\test001.bmp" For Binary Access Write As #1
Put #1, 1, strImage
Close #1

*** strImage contains binary data

when i try to open the bmp it show invalid bitmap file.

a few thoughts...

Does the file exist already? If so it may be longer than what you
write.

You don't need the ", 1": Put #1,,strImage

Using strings for binary data is good for VB3 and earlier but starting
with VB4 you get ansi/unicode translations going on and that may be
affecting you. Use a byte array instead of a string for binary data.

How are you getting the data? My guess is that's where it is getting
corrupted.

BTW, you should use the FreeFile function rather than hard-coding #1


hi Bob,

Thanks for your reply.

I m converting .asp to VB and here's the asp code...

if code <> "" then
response.binarywrite x()
for i = 1 to height
response.binarywrite y()
next
end if

notes :
The above script will combine x() and y() to generate a bitmap image and
shows in a browser.
x() and y() contains binary data of the bitmap image file.

My question is, how to save these x() and y() into a file, e.g.
"image001.bmp"?

I tried with this...
open "image001.bmp" for binary access write as #1
put #1,,x()
put #1,,y()
close #1

...but gave me a invalid bmp image.

Appreciate any helps.

Kee

Jul 17 '05 #3
kee <ke***@kee.dynu.com> wrote in message news:<40********@news.tm.net.my>...
<cut>
if code <> "" then
response.binarywrite x()
for i = 1 to height
response.binarywrite y()
next
In that code it looks to me like you are writing the y data 'i' times
open "image001.bmp" for binary access write as #1
put #1,,x()
put #1,,y()
close #1


In that code you are writing it once
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Kevin Knorpp | last post by:
Hello. I need to be able to extract the data from the attached file (or any file in the same format) so that I can work with the data in PHP. I'm fairly comfortable with using PHP with...
4
by: Tom Van Ginneken | last post by:
Hi, I need to write binary data to a serial port. I am using this function: #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); I am able to write a alpha-numeric...
6
by: leonecla | last post by:
Hi everybody, I'm facing a very very strange problem with a very very simple C program... My goal should be to write to a binary file some numbers (integers), each one represented as a sequence...
3
by: Billy Smith | last post by:
I'm trying to write a little utility that will write some binary data to a file via a javascript and Windows Script Host under Windows XP. The only way to do this that I can find is to convert...
3
by: David Warner | last post by:
Greetings! I am working on a C app that needs to read print files generated by lp that contain HP LaserJet PCL codes. If the PCL contains binary data to define a bit map to be printed on the...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
2
by: Thomi Aurel RUAG A | last post by:
Hy I'm using Python 2.4.2 on an ARM (PXA-270) platform (linux-2.6.17). My Goal is to write a list of bytes down to a file (opened in binary mode) in one cycle. The crux is that a '0x0a' (line...
4
by: Swan | last post by:
Hi,I am sending binary data from VB to ASP through HttpSendRequest API.I am getting size of file on ASP(using Request.TotalBytes),which I am sending.Now I want to write it on specific path on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.