printing - Display Large Image in c# -
i want display large image small rectangle using c#. problem when not adjust rectangle size , image, half portion of image displayed every time. there way print image in bounds defined? mean can image re-size rectangle size?
following code:
int imageprintheight = this.papersize.width - this.printmargins.top - this.printmargins.bottom; int imageprintwidth = this.papersize.height - this.printmargins.left - this.printmargins.right; size datestoprintsize = textrenderer.measuretext(datestoprint, new font(this.font.fontfamily, 10)); y = y + descriptionsize.height + datestoprintsize.height; imageprintheight = imageprintheight - descriptionsize.height - datestoprintsize.height; e.graphics.drawstring(objcurrentprintjob.sdescription, new font(this.font.fontfamily, 10), new solidbrush(color.black), x + (imageprintwidth - descriptionsize.width) / 2, this.printmargins.top); e.graphics.drawstring(datestoprint, new font(this.font.fontfamily, 10), new solidbrush(color.black), x + (imageprintwidth - datestoprintsize.width) / 2, this.printmargins.top + descriptionsize.height); } decimal ratio = math.round(decimal.divide(imagetoprint.width, imagetoprint.height), 4); int tempimageprintwidth = (int)(math.round(imageprintheight * ratio, 4)); x += (int)((imageprintwidth - tempimageprintwidth) / 2);
to print use following
e.graphics.drawimage(imagetoprint, new rectangle(x,y ,tempimageprintwidth,imageprintheight));
if understand correctly, seems trying fit image available page size. looks mix width , height when assigning imageprintheight , imageprintwidth. scaling this, allow different relations between image , page aspect ratios:
int imageprintheight = this.papersize.height- this.printmargins.top - this.printmargins.bottom; int imageprintwidth = this.papersize.width- this.printmargins.left - this.printmargins.right; // draw description string here... double ratio = math.min((double)imageprintwidth / (double)imagetoprint.width, (double)imageprintheight / (double)imagetoprint.height); int scaledimagewidth = (int)(ratio * imagewidth); int scaledimageheight = (int)(ratio * imageheight); x = (int)((imageprintwidth - scaledimagewidth ) / 2);
Comments
Post a Comment