It looks like the automatic overload resolution may be failing -- at least, it&#39;s worth trying to resolve the overload manually. This would be something like<br><br>from System import Array, Byte, IntPtr<br>Marshal.Copy.Overloads[Array[Byte], int, IntPtr, int](bytes, 0, bmData.Scan0, total_bytes)<br>
<br><br><div class="gmail_quote">On Sat, Jun 12, 2010 at 10:07 PM, Marcel <span dir="ltr">&lt;<a href="mailto:marcel.vandendungen@gmail.com">marcel.vandendungen@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I think I simplified my example a little too far. I&#39;m trying to<br>
display a Bitmap from bytes generated in Python code.<br>
<br>
        bytes = array.array(&#39;c&#39;) # tried &#39;B&#39; also<br>
        # generate bitmap bytes ...<br>
<br>
        bitmap = Bitmap(width, height, PixelFormat.Format24bppRgb)<br>
<br>
        bmData = bitmap.LockBits(Rectangle(0, 0, bitmap.Width,<br>
bitmap.Height),<br>
          ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)<br>
<br>
        total_bytes = (bmData.Stride) * bmData.Height<br>
<br>
        Marshal.Copy(bytes, 0, bmData.Scan0, total_bytes);<br>
<br>
        bitmap.UnlockBits(bmData)<br>
<br>
The IronPython exception I&#39;m getting is:<br>
TypeError: expected IntPtr, got array<br>
<br>
Casting the bytes array to IntPtr changed the error into:<br>
TypeError: expected int, got array<br>
<br>
I&#39;m using IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.4927<br>
<br>
Any idea?<br>
<br>
Thanks,<br>
-- Marcel<br>
<br>
On Jun 11, 11:27 pm, David Escobar &lt;<a href="mailto:davidesco...@ieee.org">davidesco...@ieee.org</a>&gt; wrote:<br>
&gt; This worked for me (based on the code you provided):<br>
&gt;<br>
&gt; import clr<br>
&gt; from System import Array<br>
&gt;<br>
&gt; dest = Array[str](bytes)<br>
&gt;<br>
&gt; On Fri, Jun 11, 2010 at 9:51 PM, Marcel &lt;<a href="mailto:marcel.vandendun...@gmail.com">marcel.vandendun...@gmail.com</a>&gt;wrote:<br>
&gt;<br>
&gt; &gt; I have a python method that returns a Python byte array.array(&#39;c&#39;).<br>
&gt;<br>
&gt; &gt; Now, I want to copy this array using<br>
&gt; &gt; System.Runtime.InteropServices.Marshal.Copy. This method however<br>
&gt; &gt; expects a .NET Array.<br>
&gt;<br>
&gt; &gt; import array<br>
&gt; &gt; from System.Runtime.InteropServices import Marshal<br>
&gt;<br>
&gt; &gt; bytes = array.array(&#39;c&#39;)<br>
&gt; &gt; bytes.append(&#39;a&#39;)<br>
&gt; &gt; bytes.append(&#39;b&#39;)<br>
&gt; &gt; bytes.append(&#39;c&#39;)<br>
&gt; &gt; Marshal.Copy(bytes, dest, 0, 3)<br>
&gt;<br>
&gt; &gt; Is there a way to make this work without copying the data? If not, how<br>
&gt; &gt; do I convert the data in the Python array to the .NET array?<br>
&gt;<br>
&gt; &gt; Thanks,<br>
&gt; &gt; -- Marcel<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; Users mailing list<br>
&gt; &gt; <a href="mailto:Us...@lists.ironpython.com">Us...@lists.ironpython.com</a><br>
&gt; &gt;<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Users mailing list<br>
&gt; Us...@lists.ironpython.comhttp://<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</blockquote></div><br>