Click here to Skip to main content
12,400,830 members (54,311 online)
Rate this:
 
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 26-Dec-11 2:41am
   
Not clear question. Could you post your code so that we could see?...
vidya jobin 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 13-Jan-13 10:15am
   
Why do you answer to a question from 2011? The question is solved already.
Member 9861188 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 22-Apr-13 7:56am
   
So? How exactly is this an answer to this 2 year old question that is already solved?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 7

I had this problem and read this solutions.
but when i checked my project's folder which images saved there , i understood that there is not the expected folder in my project.
so i created a new folder again for my images and my problem have solved.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 8

I faced the same issue. In my scenario all are working fine,but getting exception when saving the image.the problem is i am saving the file with special character (\), which is not acceptable. now it is working fine after changed the file name.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

public static byte[] ConvertImageToByteArray(Image imageToConvert)
{
using (var ms = new MemoryStream())
{
Bitmap bmp = new Bitmap(imageToConvert);
bmp.Save(ms, format);
return ms.ToArray();
}
}
  Permalink  
Comments
Momoaal 25-May-16 6:05am
   
Thanks Moh'd A.Hafed1K , ;)
This solution works for me .. after long time trying to solve it ...
Great work ...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 5 Nov 2014
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100