Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP
hai ,
 
c# a generic error occurred in gdi+ generated when a Print Page.jpg
pls help me
Posted 25-Dec-11 20:38pm
Comments
Al Moje at 26-Dec-11 2:41am
   
Not clear question. Could you post your code so that we could see?...
vidya jobin at 26-Dec-11 2:54am
   
I'm trying to print an Image using PrintDocumentin C# but somehow the setting (like Number of Pages and Image Quality ) are ignored while printing and preview. Is there anything wrong in following code, Am I missing something? my code below string mname=""; DialogResult result1 = MessageBox.Show("Are you want to Print the Bill", "", MessageBoxButtons.YesNo); if (result1 == DialogResult.Yes) { Graphics g1 = this.CreateGraphics(); Image MyImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, g1); Graphics g2 = Graphics.FromImage(MyImage); IntPtr dc1 = g1.GetHdc(); IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376); g1.ReleaseHdc(dc1); g2.ReleaseHdc(dc2); MyImage.Save(@"c:\PrintPage.jpg", ImageFormat.Jpeg); FileStream fileStream = new FileStream(@"c:\PrintPage.jpg", FileMode.Open , FileAccess.ReadWrite ); StartPrint(fileStream, "Image"); fileStream.Close(); if (System.IO.File.Exists(@"c:\PrintPage.jpg")) { System.IO.File.Delete(@"c:\PrintPage.jpg"); } if (type == "IPD") { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells["medname"].Value != null) { mname = mname + row.Cells["medname"].Value.ToString() + ","; SqlCommand cmd = new SqlCommand("insert into Tmedicine values('" + Tid().ToString() + "','" + label7.Text + "','" + label6.Text + "','" + row.Cells["medname"].Value + "','" + row.Cells["mdate"].Value + "','" + row.Cells["intake"].Value + "','" + row.Cells["unit"].Value + "','" + label4.Text + "','" + row.Cells["unitprice"].Value + "','" + row.Cells["qty"].Value + "','" + row.Cells["total"].Value + "')", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } else { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells["medname"].Value != null) { mname = mname + row.Cells["medname"].Value.ToString() + ","; SqlCommand cmd = new SqlCommand("insert into OutMedical values('" + oTid().ToString() + "','" + label7.Text + "','" + label6.Text + "','" + row.Cells["medname"].Value + "','" + row.Cells["mdate"].Value + "','" + row.Cells["intake"].Value + "','" + row.Cells["unit"].Value + "','" + label4.Text + "','" + row.Cells["unitprice"].Value + "','" + row.Cells["qty"].Value + "','" + row.Cells["total"].Value + "')", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } SqlCommand com = new SqlCommand("insert into phpayment values('" + label3.Text + "','" + label4.Text + "','"+DateTime.Now.ToShortTimeString()+"','" + label7.Text + "','" + label6.Text + "','" + label10.Text + "','"+mname.ToString()+"','" + textBox1.Text + "')", con); con.Open(); com.ExecuteNonQuery(); con.Close(); billid(); }
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check the permission to the folder where you are saving this JPEG file.
 
folder should be have write permissions
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

add write permission
ASP User , IUSER , NETWORK SERVICES
  Permalink  
Comments
ProgramFOX at 13-Jan-13 10:15am
   
Why do you answer to a question from 2011? The question is solved already.
Member 9861188 at 22-Apr-13 6:18am
   
MemoryStream s = new MemoryStream(); logoimage.Image.Save(s, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] pic = s.ToArray(); I have write this code.this gives error "a generic error occurred in gdi+"
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

MemoryStream s = new MemoryStream();
logoimage.Image.Save(s, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic = s.ToArray();
 

 
I have write this code.this gives error "a generic error occurred in gdi+"
  Permalink  
Comments
ThePhantomUpvoter at 22-Apr-13 7:56am
   
So? How exactly is this an answer to this 2 year old question that is already solved?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 9,225
1 OriginalGriff 5,395
2 Peter Leow 4,100
3 Maciej Los 3,540
4 Abhinav S 3,333


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 17 Jan 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid