Page 1 of 1
Image does not contain a geometry
Posted: 2016-07-19T09:34:25-07:00
by peter01242
I have created a barcode using the following code:
Code: Select all
Magick::Image Im(Magick::Geometry(600, 150), Magick::Color("white"));
Im.colorSpace(Magick::GRAYColorspace);
Im.font("CODE3X");
Im.fontPointsize(48.0);
Im.draw(Magick::DrawableText(20, 80, "*Barcode Test*"));
I want to position this at the bottom of another image (target) where (0,0) is the TLC using:
Code: Select all
size_t nHPos = target.geometry().height() - Im.geometry().height();
The line above generates the exception that is the subject of this post relating to the barcode (Im).
Why does the barcode image not have a geometry that I can access?
Any suggestions?
Pete Young
Re: Image does not contain a geometry
Posted: 2016-07-19T11:17:17-07:00
by fmw42
It might help if you provide your IM version and platform and your resulting image.
Re: Image does not contain a geometry
Posted: 2016-07-20T01:48:02-07:00
by peter01242
I am using ImageMagick-7.0.2-Q8 on Windows 10 64-bit using VS2013 Pro (Version 12.0.40629.00 Update 5)
With the original code fragment I posted there is no final image as the exception was thrown and the image was not written to disk.
Here is the code that generates the barcode and writes it to disk:
Code: Select all
// Read the image (quietly ignore any warnings, but not errors.)
Magick::Image Im(Magick::Geometry(BARCODE_WIDTH, BARCODE_HEIGHT), Magick::Color("white"));
Im.colorSpace(Magick::GRAYColorspace);
Im.font("CODE3X");
Im.fontPointsize(48.0);
Im.draw(Magick::DrawableText(20, 80, "*Barcode Test*"));
Im.magick("PNG");
Im.write("barcode.png");
Here is a link to the barcode image that the previous code fragment generates:
https://www.dropbox.com/sh/sb7ma8mh5552 ... L3uDa?dl=0
Here is a link to the image.tif file used below:
https://www.dropbox.com/s/3hu28uo4hd7hy ... e.tif?dl=0
As an interesting side note, I also tried the following:
Code: Select all
Magick::InitializeMagick(GetApplicationFolder().GetBuffer(0));
try {
Magick::Image target;
target.quiet(true);
target.read("image.tif");
Magick::Geometry geom = target.geometry();
size_t nHeightPixels = geom.height();
}
catch(Magick::Exception &error_) {
printf("Barcode() failed. %s.\r\n", error_.what());
}
The Geometry object returned from target.geometry() is empty (all fields set to zero or false), which is a little odd. I would have expected IM to have filled in at least some of these fields when it read the file and, given that this appears to be how you determine the size of the image you have read in, I find it a little worrying that no else seems to be having this problem.
Re: Image does not contain a geometry
Posted: 2016-07-20T02:17:51-07:00
by peter01242
After doing some more reading and head-scratching I decided to try rows() and columns() which appear to return the values that I require.
Having the Geometry object filled in after the read would be a nice feature addition as it does seem like a logical place to go looking for those details.
Re: Image does not contain a geometry
Posted: 2016-07-20T02:59:54-07:00
by snibgo
I don't use Magick++, but the documentation
http://www.imagemagick.org/Magick++/Image++.html describes the image attributes:
coumns: Image width
rows: The number of pixel rows in the image
geometry: Preferred size of the image when encoding.
From that, if you want the width and height of an image, the relevant attributes seem clear.