2014-03-30 1 views
1

이 코드 : Vcl.Imaging.jpeg 사용JPE 이미지 파일을로드하는 방법은 무엇입니까?

EInvalidGraphic: Unknown picture file extension <.jpe> 

하는데도 :

uses 
    Vcl.Imaging.jpeg... 
... 
ThisPicture := TPicture.Create; 
try 
    ThisPicture.LoadFromFile('MyImage.JPE'); // error 
    ... 
finally 
    ThisPicture.Free; 
end; 

이 오류가 발생합니다. JPG 및 JPEG는 문제없이로드 할 수 있습니다.

Wikipedia.jpg, .jpeg, .jpe .jif, .jfif, .jfi은 JPEG 형식의 확장입니다.

어떻게 사용할 수 있습니까? LoadFromFile ('MyImage.JPE') 오류없이 사용할 수 있습니까?

+2

프로그램 시작시 'TPicture.RegisterFileFormat ('jpe ','JPE 이미지 파일 ', TJPEGImage);를 호출하십시오. – TLama

+0

@traama TLama와 David Heffernan의 두 솔루션 모두 작동합니다! 하지만 일반적으로 솔루션을 사용하고 싶은 가장 간단한 솔루션을 선호하므로 답변으로 추가하십시오. – user1580348

답변

3

JPE 확장자는 Delphi JPEG 코드에 의해 등록되지 않았습니다. 따라서 오류. 이미지 유형을 알고 있으므로 직접 TJPEGImage 객체에로드 할 수 있습니다.

Image := TJPEGImage.Create; 
Image.LoadFromFile(...); 

그리고 그림 컨트롤에 지정합니다.

ThisPicture.Assign(Image); 

또는 JPE 확장을 등록하는 간단한 해결책이 TJPEGImageTPicture 동료 있도록. 이것은 TPicture.RegisterFileFormat을 사용하여 수행 할 수 있습니다 : 확장 정확히해야한다는

The AExtension parameter specifies the three-character system file extension to associate with the graphic class (for example, "bmp" is associated with TBitmap).

이 제안에 대해 걱정하지 마십시오 :

그것은 가치가 무엇인지에 대한
uses 
    Vcl.Imaging.JConsts, Vcl.Imaging.jpeg; 
.... 
TPicture.RegisterFileFormat('jpe', sJPEGImageFile, TJPEGImage); 
TPicture.RegisterFileFormat('jif', sJPEGImageFile, TJPEGImage); 
TPicture.RegisterFileFormat('jfif', sJPEGImageFile, TJPEGImage); 
TPicture.RegisterFileFormat('jfi', sJPEGImageFile, TJPEGImage); 

RegisterFileFormat의 문서가이 오히려 고풍스러운 라인을 포함 길이가 3 자. 이는 단순히 문서 오류 일뿐입니다.

+1

이미'TJPEGImage'를 가리 키지 않는 한'TJPEGImage'를'TPicture.Graphic'에'Assign()'할 수 없습니다. 'TPicture' 그 자체에'Assign()'하는 것이 더 좋으므로'Graphic'을 현재의 타입에 관계없이 업데이트합니다 :'ThisPicture.Assign (Image);' –

+0

@Remy 고맙습니다 –