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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kee

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

    Hi All,

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

    Open "d:\temp\test00 1.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

  • Bob Butler

    #2
    Re: how to write binary(bmp) data to a file?

    kee <[email protected] .com> wrote in message news:<40629902$ [email protected] .my>...[color=blue]
    > Hi All,
    >
    > I am trying to write binary data to a file, which is bmp image:
    >
    > Open "d:\temp\test00 1.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.[/color]

    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

    Comment

    • kee

      #3
      Re: how to write binary(bmp) data to a file?

      Bob Butler wrote:[color=blue]
      > kee <[email protected] .com> wrote in message news:<40629902$ [email protected] .my>...
      >[color=green]
      >>Hi All,
      >>
      >>I am trying to write binary data to a file, which is bmp image:
      >>
      >> Open "d:\temp\test00 1.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.[/color]
      >
      >
      > 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[/color]

      hi Bob,

      Thanks for your reply.

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

      if code <> "" then
      response.binary write x()
      for i = 1 to height
      response.binary write 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.b mp"?

      I tried with this...
      open "image001.b mp" 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

      Comment

      • Bob Butler

        #4
        Re: how to write binary(bmp) data to a file?

        kee <[email protected] .com> wrote in message news:<40639baa_ [email protected] y>...
        <cut>[color=blue]
        > if code <> "" then
        > response.binary write x()
        > for i = 1 to height
        > response.binary write y()
        > next[/color]

        In that code it looks to me like you are writing the y data 'i' times
        [color=blue]
        > open "image001.b mp" for binary access write as #1
        > put #1,,x()
        > put #1,,y()
        > close #1[/color]

        In that code you are writing it once

        Comment

        Working...