2008-08-18 3 views
9

WindowsForms 세계에서는설치된 BitmapEncoders/Decoders (WPF 세계)의 목록을 얻는 방법?

System.Drawing.ImageCodecInfo.GetImageDecoders()/GetImageEncoders() 

를 사용하여 사용 가능한 이미지 인코더/디코더 목록을 얻을 수 있습니다. 제 질문은 WPF 세계에서 사용 가능한

목록을 얻을 수있는 비슷한 것을 수행하는 방법이 있습니까?
System.Windows.Media.Imaging.BitmapDecoder/BitmapEncoder 

답변

0

내가 틀렸다면 누군가가 나를 고쳐 주시길 바랍니다.하지만 WPF에는 그런 것이 없다고 생각합니다. 그러나 이것이 기술 진보가 우리가 일을하는 데 익숙해 진 방식으로 쓸모 없게 된 많은 사례 중 하나입니다. "내 디지털 시계를 어떻게 감을 수 있습니까?"

System.Drawing에서 ImageCodecInfo.GetImageDecoders()가 필요한 이유는 System.Drawing 자체의 kludgy 특성과 관련이 있습니다. System.Drawing은 관리되지 않는 래퍼 인 GDI + 주위의 관리되는 래퍼입니다. Win32 API의 일부를 둘러 쌉니다. 그래서 .NET이 본질적으로 그것에 대해 아는 것없이 새로운 코덱이 Windows에 설치되는 이유가있을 수 있습니다. 그리고 GetImageDecoders()에서 반환되는 것은 일반적으로 System.Drawing/GDI +로 다시 전달되는 문자열로, 이미지를 읽고 저장하기위한 적절한 DLL을 찾고 구성하는 데 사용됩니다.

반면에 WPF에서는 표준 인코더와 디코더가 프레임 워크에 내장되어 있으며, 틀린 것이 아니라면 프레임 워크의 일부로 설치되지 않을 수도있는 것에 의존하지 마십시오. 프레임 워크. 다음 클래스는 BitmapEncoder에서 상속되며 BFB에서 즉시 사용할 수 있습니다. BmpBitmapEncoder, GifBitmapEncoder, JpegBitmapEncoder, PngBitmapEncoder, TiffBitmapEncoder, WmpBitmapEncoder. 같은 형식의 BitmapDecoder와 IconBitmapDecoder 및 LateBoundBitmapDecoder가 있습니다.

내가 상상할 수없는 경우를 다루고 있을지 모르지만, BitmapEncoder를 상속하지만 WPF에 포함되지 않은 클래스를 사용해야하는 경우에는 아마도 자신의 맞춤 클래스 일 것입니다. 귀하의 응용 프로그램과 함께 설치합니다.

희망이 도움이됩니다. 사진의 일부가 누락되면 알려주십시오.

+1

저는이 문제를 연구 중이며 잘못되었습니다. WPF 이미징은 System.Drawing과 동일합니다. 즉, Win32의 관리 대상 래퍼 인 WIC (Windows Imaging Component)입니다. 엔코더/디코더가 프레임 워크에 내장되어 있지 않으며, 성능 및 코드 재사용 이유가 전혀 없을 것이라고 생각합니다. Windows에서 모두 사용할 수 있습니다. 그들은 형식을 나열하는 기능을 추가하는 것을 잊어 버렸습니다. – fejesjoco

+0

: "디지털 시계를 어떻게 감 으세요?" 이제는 모션을 사용하여 배터리를 충전하는 디지털 시계를 만듭니다. 그래서 그들은 와인 더와 함께 하나를 만들 수 있습니다. :) –

4

.NET 리플렉션을 좋아해야합니다. WPF 팀에서 일했고 내 머리 꼭대기에서 더 나은 것을 생각할 수 없었습니다. 다음 코드는 내 컴퓨터에이 목록을 생성합니다

Bitmap Encoders: 
System.Windows.Media.Imaging.BmpBitmapEncoder 
System.Windows.Media.Imaging.GifBitmapEncoder 
System.Windows.Media.Imaging.JpegBitmapEncoder 
System.Windows.Media.Imaging.PngBitmapEncoder 
System.Windows.Media.Imaging.TiffBitmapEncoder 
System.Windows.Media.Imaging.WmpBitmapEncoder 

Bitmap Decoders: 
System.Windows.Media.Imaging.BmpBitmapDecoder 
System.Windows.Media.Imaging.GifBitmapDecoder 
System.Windows.Media.Imaging.IconBitmapDecoder 
System.Windows.Media.Imaging.LateBoundBitmapDecoder 
System.Windows.Media.Imaging.JpegBitmapDecoder 
System.Windows.Media.Imaging.PngBitmapDecoder 
System.Windows.Media.Imaging.TiffBitmapDecoder 
System.Windows.Media.Imaging.WmpBitmapDecoder 

가 (당신이 예를 들어 플러그인을 지원하는 경우) 추가 어셈블리를 추가 할 수있는 코드의 주석이 있습니다.

System.Windows.Media.Imaging.LateBoundBitmapDecoder 

더 정교한 필터링을 사용하여 생성자 패턴 매칭이 가능하지만, 나는 그것을 쓰는 기분이 안 : 또한, 제거 디코더 목록을 필터링 할 것입니다. :-)

지금 당신이해야 할 일은 인코더와 디코더를 인스턴스화하여 사용하는 것입니다. 또한 인코더 디코더의 CodecInfo 속성을 검색하여 더 나은 이름을 얻을 수 있습니다. 이 클래스는 다른 사실들 중에서 사람이 읽을 수있는 이름을 제공합니다.

using System; 
using System.Linq; 
using System.Collections.Generic; 
using System.Reflection; 
using System.Windows.Media.Imaging; 

namespace Codecs { 
    class Program { 
     static void Main(string[] args) { 
      Console.WriteLine("Bitmap Encoders:"); 
      AllEncoderTypes.ToList().ForEach(t => Console.WriteLine(t.FullName)); 
      Console.WriteLine("\nBitmap Decoders:"); 
      AllDecoderTypes.ToList().ForEach(t => Console.WriteLine(t.FullName)); 
      Console.ReadKey(); 
     } 

     static IEnumerable<Type> AllEncoderTypes { 
      get { 
       return AllSubclassesOf(typeof(BitmapEncoder)); 
      } 
     } 

     static IEnumerable<Type> AllDecoderTypes { 
      get { 
       return AllSubclassesOf(typeof(BitmapDecoder)); 
      } 
     } 

     static IEnumerable<Type> AllSubclassesOf(Type type) { 
      var r = new Reflector(); 
      // Add additional assemblies here 
      return r.AllSubclassesOf(type); 
     } 
    } 

    class Reflector { 
     List<Assembly> assemblies = new List<Assembly> { 
      typeof(BitmapDecoder).Assembly 
     }; 
     public IEnumerable<Type> AllSubclassesOf(Type super) { 
      foreach (var a in assemblies) { 
       foreach (var t in a.GetExportedTypes()) { 
        if (t.IsSubclassOf(super)) { 
         yield return t; 
        } 
       } 
      } 
     } 
    } 
} 
관련 문제