THotPDF.DecodeLoadedImageRegionAtResolution Method
Decodes a source-coordinate rectangle while allowing the decoder to select a lower resolution level that still satisfies the requested output size
Declaration
function DecodeLoadedImageRegionAtResolution(
AImageStream: THPDFStreamObject;
RegionLeft, RegionTop, RegionRight, RegionBottom,
TargetPixelWidth, TargetPixelHeight: Integer): TBitmap;
Unit
HPDFDoc
Parameters
| Name | Purpose |
|---|---|
AImageStream | Loaded image XObject stream to decode |
RegionLeft | Inclusive left source coordinate |
RegionTop | Inclusive top source coordinate |
RegionRight | Exclusive right source coordinate |
RegionBottom | Exclusive bottom source coordinate |
TargetPixelWidth | Minimum useful decoded width before final rendering scale |
TargetPixelHeight | Minimum useful decoded height before final rendering scale |
Return value
Returns a newly allocated bitmap for the clamped non-empty region, or nil when the image or requested geometry cannot be decoded
Resolution selection
- JPEG 2000 selects the greatest power-of-two reduction whose decoded width and height both remain at least the requested pixel size
- The selection never under-resolves either dimension and therefore avoids an unnecessary upscale before drawing
- Native region selection and resolution selection are combined before wavelet reconstruction and pixel expansion
- Crash-isolated JPEG 2000 workers receive the same reduction request and use a correspondingly smaller output budget
- When native fallback handles a region that intersects multiple codestream tiles, independent tiles decode concurrently within cancellation, worker-count, output, and peak-memory limits
- Parallel results are composed in stable row-major order and insufficient working budget transparently selects the sequential region path
- A JPEG image in DeviceRGB or DeviceGray goes through a reduced-size DCT decoder when the region or the requested size differs from the full image: it decodes at a reduced DCT scale that still covers the request and returns the region resampled to exactly the requested size
- Other supported image formats, and JPEG images in other color spaces, preserve exact region decoding and leave any final scaling to the caller
- The caller owns a non-nil returned bitmap and must free it
Example
Preview := PDF.DecodeLoadedImageRegionAtResolution(
ImageStream, 0, 0, SourceWidth, SourceHeight, 320, 200);
try
Canvas.StretchDraw(TargetRect, Preview);
finally
Preview.Free;
end;