ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 278k

when draw image on print document it return system.Byte[] an

Jan 31 2019 7:15 PM
problem
 
when draw image on print document it return system.Byte[] and not return image .

when draw image on print document it return system.Byte[] and not return image .

sql field is MemberImage with datataype varbinarymax .

on datatable of print document i defined image as

  1. DataTable table = new DataTable();  
  2.             table.Columns.Add("MemberCode"typeof(string));  
  3.             table.Columns.Add("MemberImage"typeof(Byte[]));  
  4.   
  5. if (dtDisplayDataPayment.Rows[i]["MemberImage"] != System.DBNull.Value)  
  6.                         {  
  7.                             byte[] photo_aray = (byte[])dtDisplayDataPayment.Rows[i]["MemberImage"];  
  8.                             System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();  
  9.                             Image img = (Image)converter.ConvertFrom(photo_aray);  
  10.                             newRow["MemberImage"] = imageToByteArray(img);  
  11.                         }  
  12. on print _document event i do as following  
  13.   
  14. foreach (DataColumn column in dtGetChecked.Columns)  
  15.             {  
  16.                 g.DrawRectangle(pen, x, y, width, height);  
  17.                 SizeF size = g.MeasureString(column.ColumnName, fonte);  
  18.                 float xPadding = (width - size.Width) / 2;  
  19.   
  20.                 g.DrawString(column.ColumnName, fonte, brush, x + xPadding, y + 5);  
  21.                 x += width;  
  22.             }  
  23.   
  24.   
  25.             x = 0;  
  26.             y += 30;  
  27.             int columnCount = dtGetChecked.Columns.Count;  
  28.   
  29.             foreach (DataRow row in dtGetChecked.Rows)  
  30.             {  
  31.                 for (int i = 0; i < columnCount; i++)  
  32.                 {  
  33.                     g.DrawRectangle(pen, x, y, width, height);  
  34.                     SizeF size = g.MeasureString(row[i].ToString(), font);  
  35.                     float xPadding = (width - size.Width) / 2;  
  36.                      
  37.                     g.DrawString(row[i].ToString(), font, brush, x + xPadding, y + 5);  
  38.                       
  39.                     x += width;  
  40.                 }  
  41.                 x = 0;  
  42.                 y += 30;  
  43.             }  
  44. under button print private void button1_Click(object sender, EventArgs e)  
  45.         {  
  46.             //for datatable  
  47.             PrintDocument document = new PrintDocument();  
  48.             document.PrintPage += new PrintPageEventHandler(document_PrintPage);  
  49.   
  50.             PrintPreviewDialog ppDialog = new PrintPreviewDialog();  
  51.             ppDialog.Document = document;  
  52.             ((ToolStripButton)((ToolStrip)ppDialog.Controls[1]).Items[0]).Enabled = false;  
  53.             ppDialog.Show();  

but image not display it display as system.Byte[]

so that how to solve this problem please


Answers (1)