[python-win32] passing image as string/stream from python to vb

Simon Dahlbacka simon.dahlbacka at gmail.com
Mon Nov 20 07:25:15 CET 2006


<random thought>
converting the bytes to strig via utf-8 smells like it could be a problem,
in case the byte sequence happens to map into a multibyte character
somewhere
</random thought>

On 11/20/06, Mark Hammond <mhammond at skippinet.com.au> wrote:
>
> It may be that the Unicode characters used by COM are to blame.  From the
> Python side of the world, try returning 'buffer(ob.getvalue())' - Python
> will try and return a buffer object as an array of characters, rather than
> a
> 'string' (which is Unicode).
>
> The end result is to try and ensure that 'imageBytes' is *identical* to
> the
> string passed by Python - I suspect it is not, which is the root of the
> problem.
>
> Cheers,
>
> Mark
>
> > -----Original Message-----
> > From: python-win32-bounces at python.org
> > [mailto:python-win32-bounces at python.org]On Behalf Of Michael Schulz
> > Sent: Friday, 17 November 2006 7:10 PM
> > To: python-win32 at python.org
> > Subject: [python-win32] passing image as string/stream from
> > python to vb
> >
> >
> > Hi,
> >
> > I'm a beginner on the python-win32 field, so please excuse
> > stupid questions ;-)
> >
> > We have an vb application that uses a python com server. This python
> > module generates images in a stringio object. We want to pass the
> > image as a string / stream to the vb application. This is in a way
> > working, as we get the data in vb, but the image cannot be rendered
> > there due to an exception from system.drawing.dll "invalid parameter
> > used".
> >
> > The server has a drawing method the returns the image from a stringio
> > via getvalue().
> > The relevant vb code, that should take the string and show it in an
> > image object:
> >
> > Dim bSPil As Object = CreateObject("Python.BSPil")
> > Dim imageString As String
> > imageString = bSPil.return_image()
> > Dim imageBytes() As Byte = (New UTF8Encoding()).GetBytes(imageString)
> > Dim ms As New IO.MemoryStream(imageBytes)
> > pb1.Image = System.Drawing.Image.FromStream(ms)
> >
> > The error is raised at the last line. When saving the image from
> > python to a file and reading it as a filestream in vb, the image is
> > displayed correctly. Can anybody shed some light on this.
> >
> > Thanks, Michael
> >
> > --
> > -----------------------------------------------------------
> > Michael Schulz
> > mschulz at webgis.de
> > -----------------------------------------------------------
> > _______________________________________________
> > Python-win32 mailing list
> > Python-win32 at python.org
> > http://mail.python.org/mailman/listinfo/python-win32
> >
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20061120/af97ccf2/attachment.htm 


More information about the Python-win32 mailing list