PdfImage constructor
PdfImage(
- PdfDocument pdfDocument, {
- required Uint8List image,
- required int width,
- required int height,
- bool alpha = true,
- PdfImageOrientation orientation = PdfImageOrientation.topLeft,
Creates a new PdfImage instance.
Implementation
factory PdfImage(
PdfDocument pdfDocument, {
required Uint8List image,
required int width,
required int height,
bool alpha = true,
PdfImageOrientation orientation = PdfImageOrientation.topLeft,
}) {
final im = PdfImage._(
pdfDocument,
width,
height,
orientation,
);
assert(() {
im.startStopwatch();
im.debugFill('RAW RGB${alpha ? 'A' : ''} Image ${width}x$height');
return true;
}());
im.params['/BitsPerComponent'] = const PdfNum(8);
im.params['/Name'] = PdfName(im.name);
im.params['/ColorSpace'] = const PdfName('/DeviceRGB');
if (alpha) {
final _sMask = PdfImage._alpha(
pdfDocument,
image,
width,
height,
orientation,
);
im.params['/SMask'] = PdfIndirect(_sMask.objser, 0);
}
final w = width;
final h = height;
final s = w * h;
final out = Uint8List(s * 3);
for (var i = 0; i < s; i++) {
out[i * 3] = image[i * 4];
out[i * 3 + 1] = image[i * 4 + 1];
out[i * 3 + 2] = image[i * 4 + 2];
}
im.buf.putBytes(out);
assert(() {
im.stopStopwatch();
return true;
}());
return im;
}