Help using AnnotateImage()
Posted: 2010-04-26T13:36:58-07:00
I've been at this for hours, trying various combinations to no avail. Anyway, please check out my code and let me know what I'm doing wrong.
Basically, I'm trying to create a new blank image and add text to it. So far I can create a blank image, but the text never gets annotated, even though AnnotateImage() returns true. The way I know this is that I convert the image to a YUV blob and dump it to a file. When I view the .yuv file using a yuv player is when I notice that there is no text on the image. The background values I setup appear, but no text. Please Help!
Thanks,
James
Basically, I'm trying to create a new blank image and add text to it. So far I can create a blank image, but the text never gets annotated, even though AnnotateImage() returns true. The way I know this is that I convert the image to a YUV blob and dump it to a file. When I view the .yuv file using a yuv player is when I notice that there is no text on the image. The background values I setup appear, but no text. Please Help!
Code: Select all
ImageInfo *img_info = CloneImageInfo((ImageInfo *) NULL);
Image *new_img = new Image();
DrawInfo *draw_info = new DrawInfo();
MagickPixelPacket *bg = new MagickPixelPacket();
TypeMetric metrics;
MagickBooleanType retv = MagickFalse;
unsigned long width = 300;
unsigned long height = 200;
int length1 = 0;
char *text = new char[1024];
strcpy(text, "blah blah blah blah blah");
// setup text values
draw_info->text = new char[strlen(text) * 2];
draw_info->fill.blue = QuantumRange;
draw_info->fill.green = 0;
draw_info->fill.red = 0;
draw_info->fill.opacity = 0;
// set bg values
bg->blue = QuantumRange;
bg->red = QuantumRange;
bg->green = QuantumRange;
// create a new blank image
new_img = NewMagickImage(img_info, width, height, bg);
// copy entered text to draw info var
strcpy(draw_info->text, text);
// overlay text on new image
retv = AnnotateImage(new_img, draw_info);
// convert new image to blob
void* img_blob;
(void) strcpy(img_info->filename,"text.yuv");
img_info->colorspace = YUVColorspace;
strcpy(img_info->magick, "YUV");
(void) TransformImageColorspace((Image *) new_img, YUVColorspace);
img_blob = ImageToBlob(img_info,(Image *) new_img, (size_t*) &length1 , exception);
// output to file
FILE *m_pf;
m_pf = fopen("text.yuv", "ab");
if(m_pf != NULL)
{
fwrite(img_blob , 1 , length1 , m_pf );
fclose(m_pf);
}
James