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

Daniel Krause m.daniel.krause at googlemail.com
Mon Jan 21 20:10:57 CET 2013


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20130121/405d0db8/attachment.html>


More information about the PythonDotNet mailing list