[Python.NET] How to use BitmapSource from System.Windows.Media.Imaging ?

Daniel Krause m.daniel.krause at googlemail.com
Tue Jan 22 19:33:59 CET 2013


Thanks for the reminder, I will keep the path in mind.

Python for .NET is installed using
pythonnet-2.0dev.clr4.0.win-amd64-py2.7.exe. As I understand it, it uses
.NET 4.0 as default? If that is true, it should work, but I had to add the
path to get the script running.


2013/1/21 brad at fie.us <brad at fie.us>

> You should be wary of that hard coded path.
>
> My best guess as to why the namespace is not provided is that the .net
> framework that is being loaded is pre .net 3.0.  I think python.netcompiles to 2.0 by default but I'd need to check that.
>
> That Windows.Media.Imaging namespace only became available in .net 3.0
> onward.
>
> To do this properly, you'd likely be looking to compile or use python.netin a mode that brings in the standard libs for .net 3.0 or higher.  Then it
> should just be available in the GAC for that .net version.
>
> Distributing a python script with .net dependencies can get rather ugly.
>
> -brad
>
> On Jan 21, 2013, at 2:10 PM, Daniel Krause <m.daniel.krause at googlemail.com>
> wrote:
>
> Hi Jojo,
>
> thanks for your help.
>
> The following code is running (64bit-Windows):
>
> import clr
> import sys
> sys.path.append("C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\WPF
> ")
> clr.AddReference("PresentationCore")
> from System.Windows.Media.Imaging import BitmapSource
> bitmapsrc = BitmapSource
> print bitmapsrc
>
> Console output:
> <class 'System.Windows.Media.Imaging.BitmapSource'>
>
> Best regards
> Daniel
>
>
> 2013/1/21 Jojo Maquiling <jojo.maquiling at kadjo.org>
>
>> Hi,
>> In C#, the System.Windows.Media can just be shown if you add the
>> "PresentationCore" as part of your reference. The path of
>> PresentationCore.dll is in C:\Program Files (x86)\Reference
>> Assemblies\Microsoft\Framework\v3.0 if you are using Visual Studio
>> 2008. I think that might help if you add that as your reference in
>> clr.AddReference. I found some explanation in here -
>>
>> http://social.msdn.microsoft.com/Forums/en-US/windowswic/thread/fdfff143-c1ae-41cd-bbeb-8ff6c1c879ec
>> I believe this will help you.
>>
>> HTH
>>
>> Thanks and best regards,
>>
>> Jojo Maquiling
>>
>> On Mon, Jan 21, 2013 at 3:40 AM, Daniel Krause
>> <m.daniel.krause at googlemail.com> wrote:
>> > I want to use BitmapSource from System.Windows.Media.Imaging
>> > (Documentation here:
>> >
>> http://msdn.microsoft.com/de-de/library/system.windows.media.imaging.bitmapsource(v=vs.100).aspx
>> > )
>> >
>> > It would be great if someone could help me with this, as I do not have
>> yet
>> > much experience with python for .NET, and none at all with .NET itself.
>> >
>> > My test script:
>> >
>> > import clr
>> > clr.AddReference("System.Windows")
>> > import System.Windows
>> > bitmap = System.Windows.Media.Imaging.BitmapSource()
>> >
>> > The interpreter info is:
>> > Traceback (most recent call last):
>> >   File "C:\Users\mdk\workspace\testbitmap.py", line 4, in <module>
>> >     bitmapsrc = System.Windows.Media.Imaging.BitmapSource()
>> > AttributeError: Media
>> >
>> > I tried also:
>> >
>> > import clr
>> > clr.AddReference("System.Windows.Media")
>> > import System.Windows
>> > bitmapsrc = System.Windows.Media.Imaging.BitmapSource()
>> >
>> >
>> > Traceback (most recent call last):
>> >   File "C:\Users\mdk\workspace\testbitmap.py",
>> > line 2, in <module>
>> >     clr.AddReference("System.Windows.Media")
>> > System.IO.FileNotFoundException: Unable to find assembly
>> > 'System.Windows.Media'.
>> >    bei Python.Runtime.CLRModule.AddReference(String name)
>> >
>> > And I also tried:
>> >
>> > import clr
>> > clr.AddReference("System.Windows")
>> > from System.Windows import Media
>> > bitmapsrc = Media.Imaging.BitmapSource()
>> >
>> > Traceback (most recent call last):
>> >   File
>> > "C:\Users\mdk\workspace\lr_control\src\lr_control\camera\testbitmap.py",
>> > line 3, in <module>
>> >     from System.Windows import Media
>> > ImportError: cannot import name Media
>> >
>> > _________________________________________________
>> > Python.NET mailing list - PythonDotNet at python.org
>> > http://mail.python.org/mailman/listinfo/pythondotnet
>>
>
> _________________________________________________
> Python.NET mailing list - PythonDotNet at python.org
> http://mail.python.org/mailman/listinfo/pythondotnet
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20130122/193ced8e/attachment.html>


More information about the PythonDotNet mailing list