2010-08-11 5 views
0

Il ya une image pour la surface, et un texte est écrit sur l'image pour 184 lignes de date .. Ainsi, il est prévu de voir 184 différents fichiers d'images écrites de texte sont généré avec toutes les mêmes images de fond. (Le code est déclaré ci-dessous ...)Nettoyer la surface sur WaterMark d'une image

Le problème est que le premier texte est écrit pour toutes les 184 données différentes .. Je pense que je dois supprimer quelque chose dans la boucle. Mais qu'est-ce que c'est?

for (int i = 0; i < dt.Rows.Count; i++) { 
      date = Convert.ToDateTime(dt.Rows[i]["PAYMENT_DATE"]); 
      branchCode = Convert.ToInt32(dt.Rows[i]["BRANCH_CODE"]); 
      refNum = Convert.ToInt32(dt.Rows[i]["REF_NUM"]); 
      accountNumber = Convert.ToInt32(dt.Rows[i]["ACCOUNT_NUMBER"]); 
      email = dt.Rows[i]["EMAIL"].ToString(); 
      tableCode = dt.Rows[i]["CUSTOMER_TABLE_CODE"].ToString(); 

      TranLogKey logKey = new TranLogKey(date, branchCode, refNum); 
      TranLogEntry entry = Log.SelectLogEntry(logKey, false); 
      if (Intertech.Core.Framework.Context.CurrentContext.LogEntry == null) 
       Intertech.Core.Framework.Context.CurrentContext.LogEntry = entry; 

      try { 
       receiptText = TransactionManager.GenerateReceipt(true, logKey, null, null, accountNumber, false); 
      } 
      catch (Exception exp) { 
       continue; 
      } 

      if (receiptText != null) { 
       if (receiptText.IndexOf("SURETTİR\r\n") != -1) 
        receiptText = receiptText.Substring(receiptText.IndexOf("SURETTİR\r\n") + 10).Trim(); 

       if (receiptText.IndexOf("İşlemi Yapan") != -1) 
        receiptText = receiptText.Substring(0, receiptText.IndexOf("İşlemi Yapan")); 
       if (receiptText.IndexOf("MÜŞTERİ İMZASI") != -1) 
        receiptText = receiptText.Substring(0, receiptText.IndexOf("MÜŞTERİ İMZASI")); 

       Bitmap bmp = (Bitmap)Bitmap.FromFile(imageDir); 
       Graphics g = Graphics.FromImage(bmp); 
       SizeF size; 
       Font font = new Font("Courier New", 8, FontStyle.Regular); 
       byte ALPHA = 200; 
       size = g.MeasureString(receiptText, font); 
       Bitmap waterbmp = new Bitmap((int)size.Width, (int)size.Height); 
       Graphics waterg = Graphics.FromImage(waterbmp); 
       waterg.DrawString(receiptText, font, new SolidBrush(System.Drawing.Color.Black), 2, 2); 
       DrawWatermark(ref waterbmp, ref bmp, LeftIndex, TopIndex, ALPHA); 
       bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); 

       try { 


         GoServices.Core.SendMailOutside("The Portugal Life", "[email protected]", 
            "[email protected]", " e-Wish " + email, "", new string[] { "dekont.jpg" }, new object[] { ms.ToArray() }); 

         LogNotificationState("K", refNum, accountNumber, 2, true, null, tableCode); 

       } 
       catch (Exception ex) { 
        LogNotificationState("K", 0, -1, 2, false, ex, tableCode); 
       } 

      } 



private static void DrawWatermark(ref Bitmap watermark_bm, ref Bitmap result_bm, int x, int y, byte ALPHA) { 
    System.Drawing.Color clr; 

    int py, px; 
    for (py = 0; py <= watermark_bm.Height - 1; py++) { 
     for (px = 0; px <= watermark_bm.Width - 1; px++) { 
      clr = watermark_bm.GetPixel(px, py); 
      if (clr.A != 0 || clr.R != 0 || clr.G != 0 || clr.B != 0) 
       watermark_bm.SetPixel(px, py, System.Drawing.Color.FromArgb(ALPHA, clr.R, clr.G, clr.B)); 
     } 
    } 
    Graphics gr = Graphics.FromImage(result_bm); 
    gr.DrawImage(watermark_bm, x, y); 
} 
+0

Vous devrez également afficher le code de 'DrawWatermark'. – leppie

+0

@ Je viens de publier que chaque fois que je reçois un e-mail avec le fichier jpg créé, la taille devient de plus en plus grande avec le même premier texte sur elle .... – theklc

+0

@Have un regard sur le code, j'ai ajouté le méthode de DrawWatermark – theklc

Répondre

0

Je regarderais comment vous créez le bitmap. Bitmap bmp = (Bitmap) Bitmap.FromFile (imageDir); Bitmap bmp = (bitmap) bitmap.FromFile (imageDir);

cette ligne doit-elle être présente à chaque fois, c'est-à-dire imagedir la même chose tout le temps?

Disposez-vous du bitmap généré après l'avoir créé?

ce qui se passe dans cette fonction:

DrawWatermark (ref waterbmp, ref bmp, LeftIndex, TopIndex, ALPHA);

Vous semblez alors sauvegarder le fichier bmp mais ne pas le jeter?

J'ai vu un comportement étrange de GDI + alors je commencerais ici.

+0

@ Jetez un coup d'oeil au code, j'ai ajouté la méthode de DrawWatermark – theklc

+0

catch (Exception ex) { LogNotificationState ("K", 0, -1, 2, faux, ex, tableCode); } bmp.Dispose(); bmp = null; ça ne marche pas! – theklc

+0

@ J'ai trouvé la réponse, j'ai mis le MemoryStream ms = new MemoryStream(); dans la boucle alors maintenant ça marche plutôt bien! merci – theklc