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?
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.
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.
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.
printf() function This is one of the most frequently used functions in C for output.
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); }
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(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With