Loaded Image Extraction
로드 이미지 추출은 LoadFromFile이나 LoadFromStream이 기존 PDF를 연 뒤 image XObject를 열거하고, 메타데이터를 검사하고, 지원 이미지를 TBitmap 인스턴스로 디코딩하게 합니다
Main APIs
GetLoadedImageCount는 로드된 문서에서 열거 가능한 이미지 객체 수를 반환합니다GetLoadedImageInfo는 픽셀을 디코딩하지 않고THPDFLoadedImageInfo에 객체 번호, 페이지 인덱스, 크기, 비트 심도, 색공간, filter 목록, 디코딩 가능성 메타데이터를 채웁니다ExtractLoadedImage는 선택된 이미지를 새TBitmap으로 디코딩합니다. 반환된 bitmap은 호출자가 소유합니다GetLoadedImageCountPerPage는 열거를 하나의 로드 페이지로 한정합니다
Supported sources
- data filter는
FlateDecode,LZWDecode,ASCIIHexDecode,ASCII85Decode,RunLengthDecode와 이미지 filter로 끝나는 다중 filter 체인을 포괄합니다 - 이미지 filter는
DCTDecode,JPXDecode,JBIG2Decode,CCITTFaxDecode를 포괄합니다 - 래스터 경로는 DeviceRGB, DeviceGray, Indexed, DeviceCMYK, 저비트 심도 grayscale/indexed 이미지를 포괄합니다
디코드 파라미터와 안전
DecodeParms와 그 축약 키DP는 값이 딕셔너리든 filter-parameter 배열의 마지막 딕셔너리든 해석됩니다Predictor,Colors,BitsPerComponent,Columns는 Flate/LZW 압축 해제 뒤에 적용됩니다- LZW
EarlyChange=0과EarlyChange=1은 모두 존중됩니다 - TIFF Predictor 2는 packed 1/2/4비트 샘플과 8/16비트 구성 요소를 지원합니다
- PNG predictor는 완전한 행마다 유효한 filter tag를 요구합니다
- 래스터 차원과 예상 바이트 수는 할당·디코딩 전에 오버플로를 검사합니다
- malformed 압축 데이터는 디코딩 실패로 보고되며 비압축 픽셀로 취급되지 않습니다
예제
var
Doc: THotPDF;
Info: THPDFLoadedImageInfo;
Bmp: TBitmap;
I: Integer;
begin
Doc := THotPDF.Create(nil);
try
Doc.LoadFromFile('input.pdf');
for I := 0 to Doc.GetLoadedImageCount - 1 do
if Doc.GetLoadedImageInfo(I, Info) and Info.Decodable then
begin
Bmp := Doc.ExtractLoadedImage(I);
try
if Assigned(Bmp) then
Bmp.SaveToFile(Format('image-%d.bmp', [I]));
finally
Bmp.Free;
end;
end;
finally
Doc.Free;
end;
end;