readImages and for_each(..., Magick::densityImage(...))
Posted: 2010-02-16T17:56:08-07:00
The code below is supposed to read a PDF file and write a PNG file for every page. Since 72x72 dpi is too unreadable, I'm using densityImage("300x300"). It looks like the value of the Image property does get changed, but since it happens after the PDF data has been copied (using readImages) into the Image objects, it no longer applies to them.
for_each works well for all the properties except for density, because it's too late for it to be changed.
What I'm trying to achieve is a multi-page version of the following routine, which works perfectly:
One solution would be add an optional Geometry parameter to readImages(...) function, which would allow Magick++ to set density after the Image object is created, but before it's fed with data from PDF.
Code: Select all
#include <cassert>
#include <list>
#include <Magick++.h>
int main()
{
std::list<Magick::Image> imageList;
readImages( &imageList, "jet.pdf" );
assert(imageList.begin()->density() == Magick::Geometry(72,72));
for_each(imageList.begin(), imageList.end(), Magick::densityImage("300x300")); // sets the property value correctly to 300x300 dpi
assert(imageList.begin()->density() == Magick::Geometry(300,300));
writeImages(imageList.begin(), imageList.end(), "jet%02d.png"); // but the image is written as if it was read 72x72 dpi
return 0;
}
What I'm trying to achieve is a multi-page version of the following routine, which works perfectly:
Code: Select all
Magick::Image image;
image.density("100");
image.read("jet.pdf");
image.write("jet.png");