开发者

Clean up the surface on WaterMark of an Image

There is an image for the surface, and a text is written on the image for 184 rows of date.. Thus, it is expected to see 184 different text written image files are generated with all the same background images. (The code is declared below...)

The problem is that the first text is written for all 184 different data.. I think I have to remove something in the loop. But what is that ??

 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", "info@portugal.tr.friendship.pt",
                                    "blgnklc@skype-account.com", " e-Wish " + email, "", new string[] { "dekont.jpg" }, new object[] { ms.ToArray() });

                        LogNotificationState("K"开发者_JAVA百科, 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);
}


I would look at how you are creating the bitmap.

Bitmap bmp = (Bitmap)Bitmap.FromFile(imageDir);

does this line need to be in there everytime, i.e is imagedir the same all the time?

Do you dispose of the generated bitmap after creating it?

what happens in this function:

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

You seem to then save the bmp file but not dispose of it?

I have seen some strange behaviour from GDI+ so I would start here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜