2011-09-14 5 views
0

wpf의 BitmapImage에 문제가 있습니다. 내가 만들 때 그것은 PresentationCore.resources 어셈블리가 없다는 filenotfound 예외를 제공합니다. 하지만 난 내 참조 목록에 추가 한 그것은 여전히 ​​같은 예외건설중인 BitmapImage filenotfound 예외 (PresentationCore.resources)

Uri filename = new Uri(@"D:\barcode_zwart_wit.jpg", UriKind.Absolute); 
BitmapImage image = new BitmapImage(filename); //<-- FileNotFound Exception 
  • 이미지 URI가 올바른지 발생합니다.
  • 이미지가 다른 곳에서 열리지 않음
  • PresentationCore.resources의 버전을 확인했지만 문제는 없습니다.
  • 줄은 사용자 정의 컨트롤의 생성자에서 처음 시작되는 속성의 설정자에 있습니다.
  • 비주얼 스튜디오 2010
    , .NET v4를

사람이 문제가 무엇 어떤 생각을 가지고 있습니까? PresentationCore.resources에는 내가 모르는 종속성이 있습니까?

+0

초기화 후에 "filename"값이 설정되어 있는지 확인할 수 있습니다. 파일 경로에 문제가 있다고 의심됩니다. –

+0

이 이미 있었지만 파일 이름이 잘못되었을 때 다른 예외가 있습니다. – hcb

+0

다음과 같은 이유 때문에 작동하지 않을 수 있습니다. 1. 위치에 액세스 할 수 없습니다. 2. 파일 형식이 지원되지 않습니다. 3. 이미지가 다른 응용 프로그램에 의해 수정되고 있습니다. 다른 사람이 귀하의 질의에 답변하기 위해 더 많은 세부 정보를 게시해야 할 수도 있습니다. –

답변

0

AppDomain.CurrentDomain.AssemblyResolve를 사용하여 해결했습니다. 특정 어셈블리를 찾을 수없는 경우 호출되는 이벤트입니다. 생성자에서

:

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); 

CurrentDomain_AssemblyResolve :

Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) 
{ 
    string missingAssemblyName = args.Name.Remove(args.Name.IndexOf(','); 
    if (missingAssemblyName == "PresentationCore.resources") 
    { 
     string s = "C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PresentationCore.resources.dll"; 
     return Assembly.LoadFile(s); 
    } 
    return; 
} 
1

문제는 이미지의 색상 프로파일을 사용할 수있는 함께 할 수 있습니다. 아래 색상 프로파일 정보를 무시 BitmapImage.CreateOptions 속성을 사용

var bmp = new BitmapImage(); 
bmp.BeginInit(); 
bmp.CreateOptions = BitmapCreateOptions.IgnoreColorProfile; 
bmp.UriSource = uri; 
bmp.EndInit(); 
// Use the bmp variable for further processing and dispose it 

나는 .jpg 이미지의 몇 가지와 같은 문제를 가지고이 그것을 해결.

관련 문제