[IronPython] Functions requiring a byte[]

Michael Foord fuzzyman at voidspace.org.uk
Sat Feb 14 14:51:38 CET 2009


Josh Green wrote:
> Hi Guys,
>
> Just to be honest from the start, I am a .NET/Python newbie, I'm at 
> home in standard C++ so please bare with me!
>
> Bascially an application that I am trying to script (FX Composer) uses 
> IronPython. One of the .NET methods exposed into python bares the 
> following signature:
>
> public void LoadRawData(byte[] bytes, int width, int height, int 
> depth, FXComposer.Scene.FXFormat format, 
> FXComposer.Scene.Effects.FXSurfaceType type)
>
> Now, my problem lies in passing information into that function in the 
> form of "byte[]".
> How can I generate a value that this function will accept in that spot?
>
> I have tried the following:
> img.LoadRawData([255,255,255,0,0,0,0,0,0,255,255,255], 2, 2, 3, 
> FXFormat.R8G8B8, FXSurfaceType.Surface2D)
>
> But it complains with the following error:
> TypeError: expected Array, got list
> CLR Exception:
>     ArgumentTypeException
> :
> expected Array, got list
>
> So I assume I have to create an array somehow... But I don't know how!

 >>> from System import Array, Byte
 >>>
 >>> a = Array[Byte]((1, 2, 45, 87))
 >>> a
Array[Byte]((<System.Byte object at 0x000000000000002B [1]>, 
<System.Byte objec
 at 0x000000000000002C [2]>, <System.Byte object at 0x000000000000002D 
[45]>, <
ystem.Byte object at 0x000000000000002E [87]>))
 >>>

>
> Any help you guys can give me would be fantastic, and any suggestions 
> of places where I might find relevant documentation on these issues 
> (CLR type conversion to Python types, etc) I would be grateful for 
> your advice.
>

IronPython in Action is an awesome resource. ;-)

Otherwise places like the IronPython cookbook are a good place to start: 
http://www.ironpython.info

All the best,


Michael Foord

> Thanks for your time
>
> Josh
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog





More information about the Ironpython-users mailing list