Cannot import System.Windows.Media.Imaging and System.Windows.Forms or System.Reflect

andycee

Member
Joined
Mar 24, 2006
Messages
11
Programming Experience
1-3
Hi,

I have an odd problem in my project.

With the following imported namespaces in my project :

VB.NET:
Imports System.Windows.Forms
Imports System.Reflection

.. I cannot add..

VB.NET:
Imports System.Windows.Media.Imaging

If I remove the Forms and Reflection namespaces, I CAN add add the Media.Imaging namespace.

Whats going on here then ?
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,604
Location
Norway
Programming Experience
10+
Both a Forms namespace and a WPF namespace in same project, sure about that? It is possible, but also a good reason you may have something mixed up... Apart from that there should be no reason both namespaces can't be imported as long as the correct assemblies are referenced.
 

andycee

Member
Joined
Mar 24, 2006
Messages
11
Programming Experience
1-3
The project is a Form based picture viewer, but I also need to read the image metadata which is done with JpegBitmapDecoder, BitmapFrame, InPlaceBitmapMetadataWriter - part of the System.Windows.Media.Imaging namespace.

Sorry if I'm misunderstanding the co-existance of WPF and Forms....

Try it in a blank project - I get the following when the Windows.Forms or .Reflection namespaces are added as well :

Warning 1 Namespace or type specified in the Imports 'System.Windows.Media.Imaging' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,604
Location
Norway
Programming Experience
10+
I don't know the JpegBitmapDecoder, or if you need it, but this class (and namespace) is part of PresentationCore assembly (a WPF assembly), which is not refereced by default in a Forms project, you have to add reference to it before you can use it.
Are you sure you can't get the metadata from Image.PropertyItems or other properties of Image ?
 

andycee

Member
Joined
Mar 24, 2006
Messages
11
Programming Experience
1-3
Are you sure you can't get the metadata from Image.PropertyItems or other properties of Image ?

Yes, a good suggestion. I have managed to retrieve the image rating this way using

VB.NET:
Dim pItem As PropertyItem = image.GetPropertyItem(18246)

however I can't seem to find a way of extracting the image (descriptive) tags - they don't appear to be in the PropertyItem metadata.

BTW, I came across this excellent article which at least explains the problems with co-existing namespaces in different versions :

VSJ | Articles | Reading, writing and photo metadata

"The latest version of the .NET Framework, i.e. .NET 3.0, has a much better approach to properties, but it too has its problems. If you download the .NET 3.0 runtime and/or the SDK, you can make use of the new .NET 3.0 classes, but it also introduces a completely new graphics environment – Windows Presentation Foundation (WPF) – and a new set of forms and controls which aren’t compatible with the old .NET 2.0 Windows Forms classes. Of course you could just opt to create a WPF application and forget about Windows Forms, but what about existing applications?"

The quest continues...
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
however I can't seem to find a way of extracting the image (descriptive) tags - they don't appear to be in the PropertyItem metadata.

Are these not encoded as byte arrays?
 
Top Bottom