c# - How to center the image jpg in the preview window? -


when printing jpg images have problem.

when displayed in preview window image not centered. how center image jpg in preview window?

private void printjpg_click(object sender, eventargs e) {     photo = image.fromfile(@"c:\...\Рисунок.jpg");      printdocument printdoc = new printdocument();     printdoc.printpage += new printpageeventhandler(printdocument1_printpage);     printpreviewdialog dlg = new printpreviewdialog();     dlg.height = 1000;     dlg.width = 1000;     dlg.document = printdoc;      dlg.showdialog(); }  private void printdocument1_printpage(object sender, system.drawing.printing.printpageeventargs e) {     graphics g = e.graphics;     g.pageunit = graphicsunit.inch;      graphics gg = graphics.fromimage(photo);      rectanglef marginbounds = e.marginbounds;     if (!printdocument1.printcontroller.ispreview)         marginbounds.offset(-e.pagesettings.hardmarginx, -e.pagesettings.hardmarginy);      float x = marginbounds.x / 100f + (marginbounds.width / 100f - (float)photo.width / gg.dpix) / 2f;     float y = marginbounds.y / 100f + (marginbounds.height / 100f - (float)photo.height / gg.dpiy) / 2f;      g.drawimage(photo, x, y);      //don't call g.dispose(). operating system job.     gg.dispose();//you should call release graphics object immediately. } 


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -