Reporting Service报表水印的添加

上一篇文章寫到了自帶報表的製作,現在來談談報表水印的添加

1:水印產生代碼

using System;
using System.Data;
using System.Configuration;
using System.Drawing;
using System.Drawing.Imaging;

/// <summary>
/// WatermarkCreater 的摘要描述
/// </summary>
public class WatermarkCreater
{
    public WatermarkCreater()
    {
        //
        // TODO: 在此加入建構函式的程式碼
        //
    }

    private Bitmap CreateImage(string code, string width, string height, string pLeft, string pTop, string font, string fColor, string bColor, string r)
    {
        Color cF = Color.FromArgb(int.Parse(fColor.Substring(2, 2), System.Globalization.NumberStyles.AllowHexSpecifier), int.Parse(fColor.Substring(4, 2), System.Globalization.NumberStyles.AllowHexSpecifier), int.Parse(fColor.Substring(6, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
        Color cB = Color.FromArgb(int.Parse(bColor.Substring(2, 2), System.Globalization.NumberStyles.AllowHexSpecifier), int.Parse(bColor.Substring(4, 2), System.Globalization.NumberStyles.AllowHexSpecifier), int.Parse(bColor.Substring(6, 2), System.Globalization.NumberStyles.AllowHexSpecifier));

        System.Drawing.SolidBrush sb = new SolidBrush(cF);
        string[] fstr = font.Split(',');
        Font f = new Font(fstr[0].Split('=')[1], (float)Convert.ToInt32(fstr[1].Split('=')[1]), FontStyle.Regular, (GraphicsUnit)Convert.ToInt32(fstr[2].Split('=')[1]), Convert.ToByte(fstr[3].Split('=')[1]), Convert.ToBoolean(fstr[4].Split('=')[1]));
        Bitmap bmp = new Bitmap(Convert.ToInt32(width), Convert.ToInt32(height));
        Graphics g = Graphics.FromImage(bmp);
        g.Clear(Color.White);
        g.RotateTransform((float)Convert.ToDouble(r));
        g.DrawString(code, f, sb, new PointF(Convert.ToInt32(pLeft), Convert.ToInt32(pTop)));

        return bmp;
    }

    public byte[] GetImageByte(string code, string config)
    {
        string[] configs = config.Split(';');
        Bitmap im = CreateImage(code, configs[0].Split(':')[1], configs[1].Split(':')[1], configs[2].Split(':')[1], configs[3].Split(':')[1], configs[4], configs[5].Split(':')[1], configs[6].Split(':')[1], configs[7].Split(':')[1]);
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        im.Save(ms, ImageFormat.Bmp);
        return ms.GetBuffer();
    }
}

 

2:把水印保存到數據庫,數據庫類型為image

3:把水印查詢出來,作為數據源傳進報表,然後在報表的背景添加即可

 

posted @ 2013-10-11 15:21  清风君  阅读(1708)  评论(0编辑  收藏  举报