How do I use PDFDraw to rasterize a single annotation?

Q:

How can I convert a single annotation to an image?

A:

To rasterize only one section of a page, you can reduce the crop box to the area you want (as shown in Example 5 of https://www.pdftron.com/pdfnet/samplecode.html#PDFDraw). For an annotation, you can grab its bounding box by calling GetRect(), then converting its coordinates from user coordinate space (which is what annotations are in) to page coordinate space (as shown in https://groups.google.com/d/msg/pdfnet-sdk/TE3Eoay3J7A/ERvDxTm5SdwJ).

The resulting code would look something like the following:

Rect box = stamp_annot.GetRect();
Matrix2D m = first_page.GetDefaultMatrix();

double x1=box.x1, y1=box.y1;
m.Mult(ref x1, ref y1);

double x2=box.x2, y2=box.y2;
m.Mult(ref x2, ref y2);

first_page.SetCropBox(new Rect(x1, y1, x2, y2));