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: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Michael Schulz
> Sent: Friday, 17 November 2006 7:10 PM
> To: python-win32@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
> [EMAIL PROTECTED]
> -----------------------------------------------------------
> _______________________________________________
> Python-win32 mailing list
> Python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
>

_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to