Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print images c#.net

I have an image in a PictureBox, and I want to print it. No formatting, no nothing, just print it.

I've been searching on Google but I've got nothing, only people printing forms or text or reports.

private string imgSrc;      public string ImgSrc     {         get { return imgSrc; }         set { imgSrc = value; }     }      public Id_Manager()     {         ImgSrc = "D:\\Foto.jpg";          InitializeComponent();         idPicture.Load(this.ImgSrc);     } 

Obviously the image is going to change, but for now I'm just interested in printing that image. I'm saving the url in a property just in case. Any help?

like image 921
Carlos Guillermo Bolaños Lopez Avatar asked Apr 21 '11 22:04

Carlos Guillermo Bolaños Lopez


People also ask

How can I display image in C?

The C language itself doesn't have any built-in graphics capability. You can use a graphics toolkit like Qt, gtk, wxWidgets, etc. You could also construct an image file (BMP is pretty simple), and then launch (using fork and exec) an application to view it.

Can you print on C?

You can print all of the normal C types with printf by using different placeholders: int (integer values) uses %d. float (floating point values) uses %f. char (single character values) uses %c.

Can we add images in C?

The C program is compiled and runs on the server, this is different from Javascript which runs on the browser. You can also generate images via CGI too. Just set the content type appropriately, eg. image/jpeg for a JPEG image.

What command prints the screen in C?

printf() function This is one of the most frequently used functions in C for output.


2 Answers

The Code below uses the PrintDocument object which you can place an image on to the printdocument and then print it.

using System.Drawing.Printing; ... protected void btnPrint_Click(object sender, EventArgs e) {     PrintDocument pd = new PrintDocument();     pd.PrintPage += PrintPage;     pd.Print();        }  private void PrintPage(object o, PrintPageEventArgs e) {     System.Drawing.Image img = System.Drawing.Image.FromFile("D:\\Foto.jpg");     Point loc = new Point(100, 100);     e.Graphics.DrawImage(img, loc);      } 
like image 120
Robbie Tapping Avatar answered Oct 02 '22 22:10

Robbie Tapping


Using the location, I have this FileInfo extension method that does it:

public static void Print(this FileInfo value) {     Process p = new Process();     p.StartInfo.FileName = value.FullName;     p.StartInfo.Verb = "Print";     p.Start(); } 
like image 29
Chuck Savage Avatar answered Oct 02 '22 21:10

Chuck Savage