unsigned char array -> buffer

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

    #1

    unsigned char array -> buffer

    Hi again,

    as I already wrote, I'm trying to get image binary data into a var holding
    an unsigned char string and then print it directly to the browser.
    I now already did some tries with an array and now found the buffer()
    function. - I thought I would have the solution now and also changed stdout
    to O_BINARY, but still I don't get the data right:

    8<--------8<--------8<--------8<--------8<--------

    imgObj = win32com.client .Dispatch("mine .imgsender")
    myImgData = buffer(imgObj.g etImgData())

    msvcrt.setmode( sys.stdout.file no(), os.O_BINARY)
    sys.stdout.writ e(myImgData)

    8<--------8<--------8<--------8<--------8<--------

    I'm really lost and would be very thankful if someone could help me with
    that.

    Many thanks in advance,
    yours Henri

    --
    | Henri Schomäcker - BYTECONCEPTS, VIRTUAL HOMES
    |     Datendesign für Internet und Intranet
    |         http://www.byteconcepts.de
    |         http://www.virtual-homes.de
  • Diez B. Roggisch

    #2
    Re: unsigned char array -&gt; buffer

    Henri Schomaecker wrote:[color=blue]
    > as I already wrote, I'm trying to get image binary data into a var holding
    > an unsigned char string and then print it directly to the browser.
    > I now already did some tries with an array and now found the buffer()
    > function. - I thought I would have the solution now and also changed
    > stdout to O_BINARY, but still I don't get the data right:
    >
    > 8<--------8<--------8<--------8<--------8<--------
    >
    > imgObj = win32com.client .Dispatch("mine .imgsender")
    > myImgData = buffer(imgObj.g etImgData())
    >
    > msvcrt.setmode( sys.stdout.file no(), os.O_BINARY)
    > sys.stdout.writ e(myImgData)
    >
    > 8<--------8<--------8<--------8<--------8<--------
    >
    > I'm really lost and would be very thankful if someone could help me with
    > that.[/color]

    That snipplet of code is totally useless, as none of us has your custom
    mine.imgsender lying around his harddisk, so we can't possibly know what
    data you get, let alone what data you want.

    So if you provided us with the actual data that is returned by getImgData we
    might be able to help.

    --
    Regards,

    Diez B. Roggisch

    Comment

    • Henri Schomaecker

      #3
      Re: unsigned char array -&gt; buffer

      Hi Diez,

      oh, I thought I made it clear: The data is a jpg image.
      Let me try to explain it like that:

      I create a com object, which loads a jpg image and then I request that image
      from the com object with the method getImgData().
      As answer to getImageData(), the com object returns a SafeArray of unsigned
      char (Bytes).

      My problem (no problem with asp and perl, same with php) is, that I would
      like to read the imagedata directly into a string of unsigned chars and
      then print it to the user agent (webbrowser) in binary mode.

      So, it would not really make sense to print the imagedata here ;-) - Sorry
      for that confusion.

      I hope it's clear now and would be very glad, If maybe you could help me.
      Again, many thanks in advance,
      yours Henri


      Diez B. Roggisch wrote:
      [color=blue]
      > Henri Schomaecker wrote:[color=green]
      >> as I already wrote, I'm trying to get image binary data into a var
      >> holding an unsigned char string and then print it directly to the
      >> browser. I now already did some tries with an array and now found the
      >> buffer() function. - I thought I would have the solution now and also
      >> changed stdout to O_BINARY, but still I don't get the data right:
      >>
      >> 8<--------8<--------8<--------8<--------8<--------
      >>
      >> imgObj = win32com.client .Dispatch("mine .imgsender")
      >> myImgData = buffer(imgObj.g etImgData())
      >>
      >> msvcrt.setmode( sys.stdout.file no(), os.O_BINARY)
      >> sys.stdout.writ e(myImgData)
      >>
      >> 8<--------8<--------8<--------8<--------8<--------
      >>
      >> I'm really lost and would be very thankful if someone could help me with
      >> that.[/color]
      >
      > That snipplet of code is totally useless, as none of us has your custom
      > mine.imgsender lying around his harddisk, so we can't possibly know what
      > data you get, let alone what data you want.
      >
      > So if you provided us with the actual data that is returned by getImgData
      > we might be able to help.
      >[/color]

      --
      | Henri Schomäcker - BYTECONCEPTS, VIRTUAL HOMES
      |     Datendesign für Internet und Intranet
      |         http://www.byteconcepts.de
      |         http://www.virtual-homes.de

      Comment

      • Diez B. Roggisch

        #4
        Re: unsigned char array -&gt; buffer

        Hi,
        [color=blue]
        > I create a com object, which loads a jpg image and then I request that
        > image from the com object with the method getImgData().
        > As answer to getImageData(), the com object returns a SafeArray of
        > unsigned char (Bytes).
        >
        > My problem (no problem with asp and perl, same with php) is, that I would
        > like to read the imagedata directly into a string of unsigned chars and
        > then print it to the user agent (webbrowser) in binary mode.
        >
        > So, it would not really make sense to print the imagedata here ;-) - Sorry
        > for that confusion.[/color]

        It will - as one can see what you actually get, instead of what you _want_
        to get. AFAIK win32 converts variants to appropriate python types, with
        arrays returned as lists - so if things work as documented, you shold get
        something like this:

        l = ["a", "$", ...]

        Making that a (binary) string should be a simple matter of

        l.join("")

        So I'd like to know what you really get- of cours the first few lines are
        sufficient, no need to post a 100kb jpeg binary image.


        --
        Regards,

        Diez B. Roggisch

        Comment

        • Michel Claveau - abstraction méta-galactique non t

          #5
          Re: unsigned char array -&gt; buffer

          Bonsoir !

          Hi !




          Attention, risque de problème (confusion) avec les chaînes à zéro terminal.

          Attention, risk of problem (confusion) with the string with zero terminal.




          *sorry for my bad english*




          @-salutations
          --
          Michel Claveau





          Comment

          • Wayne Witzel III

            #6
            Re: unsigned char array -&gt; buffer

            > My problem (no problem with asp and perl, same with php) is, that I would[color=blue]
            > like to read the imagedata directly into a string of unsigned chars and
            > then print it to the user agent (webbrowser) in binary mode.
            >[/color]
            # this example assumes you are using PIL
            # this example assume mod_python, but can be easily modified.
            def displayJpeg():
            im = Image.Open(file )
            imdata = StringIO()
            im.save(imdata, "JPEG")
            del im

            req.content_typ e = "Content-type: image/jpeg"
            return imdata.getValue ()

            Hope this helps in some way? I think I might have misunderstood the
            question though.

            Comment

            Working...