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?
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  
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  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 545
1 CPallini 490
2 George Jonsson 297
3 OriginalGriff 250
4 Suvabrata Roy 209
0 OriginalGriff 4,873
1 CPallini 3,900
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,646
4 Gihan Liyanage 2,236


Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 25 Jun 2014
Copyright © CodeProject, 1999-2014
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