MagickAnnotateImage() Layer?

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
zoomcityzoom

MagickAnnotateImage() Layer?

Post by zoomcityzoom »

Here's a snippet of code that creates a 600x800 canvas, draws a 10x10 grid, a rounded rectangle, a curve and then some text. The rounded rectangle is drawn over top of the grid. The curve is drawn over top of the rounded rectangle and the grid. The text, however, is drawn under the grid. Is there a way to force the text to appear over top of the grid or whatever else was previously drawn?

Thanks,
Tom

Code: Select all

     MagickWandGenesis();

     m_wand = NewMagickWand();
     d_wand = NewDrawingWand();
     c_wand = NewPixelWand();

     /* Create a new image with specified background
      */
     PixelSetColor(c_wand,"white");
     MagickNewImage(m_wand, 600, 800, c_wand);

     DrawSetStrokeOpacity(d_wand,1);


     /* Draw 10 x 10 lightblue grid on background
      */
     int i;
     PushDrawingWand(d_wand);
     PixelSetColor(c_wand, "lightblue");
     DrawSetStrokeColor(d_wand, c_wand);
     DrawSetStrokeWidth(d_wand, 1);
     // Draw horizontal lines
     for (i = 0; i < 800; i += 10)
          DrawLine(d_wand, 0, i, 600, i);
     // Draw vertical lines
     for (i = 0; i < 600; i += 10)
          DrawLine(d_wand, i, 0, i, 800);
     PopDrawingWand(d_wand);



     /* Draw a rounded rectangle
      */
     PushDrawingWand(d_wand);
     PixelSetColor(c_wand,"yellow");
     DrawSetStrokeColor(d_wand, c_wand);

     DrawSetStrokeWidth(d_wand, 4);
     DrawSetStrokeAntialias(d_wand, 1);

     PixelSetColor(c_wand, "blue");
     DrawSetStrokeOpacity(d_wand, 1);
     DrawSetFillColor(d_wand, c_wand);

     DrawRoundRectangle(d_wand, 30, 30, 100, 100, 10, 10);
     PopDrawingWand(d_wand);


     /* Draw a curve
      */
     PushDrawingWand(d_wand);
     {
          const PointInfo points[4] =
               {
                    { 20, 20 }, { 100, 50 }, { 50, 100 }, { 160, 160 }
               };

          PixelSetColor(c_wand, "none");
          DrawSetFillColor(d_wand, c_wand);
          PixelSetColor(c_wand,"black");
          DrawSetStrokeColor(d_wand, c_wand);
          DrawSetStrokeWidth(d_wand, 4);

          DrawBezier(d_wand, 4, points);
          PopDrawingWand(d_wand);
     }


     /* Draw text
      */
     PushDrawingWand(d_wand);
     DrawSetFontSize(d_wand, 64);
     PixelSetColor(c_wand, "red");
     DrawSetFillColor(d_wand, c_wand);
     PixelSetColor(c_wand,"red");
     DrawSetStrokeColor(d_wand, c_wand);
     MagickAnnotateImage(m_wand, d_wand, 100, 340, 45, "Apple Engineering Rocks!");
     PopDrawingWand(d_wand);
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: MagickAnnotateImage() Layer?

Post by el_supremo »

Immediately before you draw the text, you can render the drawingwand onto the magickwand, clear it and then do the text, like this:

Code: Select all

	MagickDrawImage(m_wand,d_wand);	
	if(d_wand)d_wand = DestroyDrawingWand(d_wand);
	d_wand = NewDrawingWand();
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
zoomcityzoom

Re: MagickAnnotateImage() Layer?

Post by zoomcityzoom »

Thanks, Pete. I appreciate your quicker than lightning response!

Tom
Post Reply