It looks like the automatic overload resolution may be failing -- at least, it'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"><<a href="mailto:marcel.vandendungen@gmail.com">marcel.vandendungen@gmail.com</a>></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'm trying to<br>
display a Bitmap from bytes generated in Python code.<br>
<br>
bytes = array.array('c') # tried 'B' 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'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'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 <<a href="mailto:davidesco...@ieee.org">davidesco...@ieee.org</a>> wrote:<br>
> This worked for me (based on the code you provided):<br>
><br>
> import clr<br>
> from System import Array<br>
><br>
> dest = Array[str](bytes)<br>
><br>
> On Fri, Jun 11, 2010 at 9:51 PM, Marcel <<a href="mailto:marcel.vandendun...@gmail.com">marcel.vandendun...@gmail.com</a>>wrote:<br>
><br>
> > I have a python method that returns a Python byte array.array('c').<br>
><br>
> > Now, I want to copy this array using<br>
> > System.Runtime.InteropServices.Marshal.Copy. This method however<br>
> > expects a .NET Array.<br>
><br>
> > import array<br>
> > from System.Runtime.InteropServices import Marshal<br>
><br>
> > bytes = array.array('c')<br>
> > bytes.append('a')<br>
> > bytes.append('b')<br>
> > bytes.append('c')<br>
> > Marshal.Copy(bytes, dest, 0, 3)<br>
><br>
> > Is there a way to make this work without copying the data? If not, how<br>
> > do I convert the data in the Python array to the .NET array?<br>
><br>
> > Thanks,<br>
> > -- Marcel<br>
> > _______________________________________________<br>
> > Users mailing list<br>
> > <a href="mailto:Us...@lists.ironpython.com">Us...@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>
><br>
><br>
><br>
> _______________________________________________<br>
> Users mailing list<br>
> 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>