Print portion of image inside Annotation with Margins

Discussions about document printing in GdPicture.NET using GdPictureImaging.
Post Reply
Posts: 1
Joined: Tue Aug 06, 2013 9:09 pm

Print portion of image inside Annotation with Margins

Post by dblwizard » Tue Aug 06, 2013 9:36 pm


I'm building an application that displays an image and then overlays an AnnotationRectangle on the image that the user can drag around the image. Think of this as a "window" on the picture. Once the user gets the "window" where they want it they then print, printing only the portion of the image that is in the window. I also need to control where on the paper the image prints.

I've got code to print the portion of the image partially working but not completely. My calculations must be a little off as the printing starts farther to the right of the original image than the window is sitting.

I can't find anyway to control the starting location of the image on the printer. My guess is I'm going to have to use the .net System.Drawing.Printing.PrintDocument and System.Drawing.Image objects but I don't see how to get an Image object from the GdPicture library.

//_image is class variable of type GdPictureImaging
//_imageID is an int of the current image.
private void btnPrint_Click(object sender, EventArgs e)
int left = 0;
int top = 0;
int height = 0;
int width = 0;

GdPictureStatus status = new GdPictureStatus();
float xRes = _image.GetHorizontalResolution(_imageID);
float yRes = _image.GetVerticalResolution(_imageID);

//Annotation Left & Top property are to the center of the Annotation so I'm subtracting
//half of the size of the Annotation.
left = (int)((_highlighter.Left - (_highlighter.Width /2)) * xRes);
top = (int)((_highlighter.Top - (_highlighter.Height /2)) * yRes);
width = (int)(_highlighter.Width * xRes);
height = (int)(_highlighter.Height * yRes);
status = _image.Crop(_imageID, left, top, width, height);

if (status == GdPictureStatus.OK)
MessageBox.Show("Error cropping image. Status:" + status.ToString());

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest