给图片添加水印的asp.net函数

Admin | 2009-1-10 20:41:43 | TrackRecord: 1660 Times | Tag标签:asp.net 打印本页

您当前所处的位置是:〖首页〗→【文章页】 本站共有16个图文教程栏目,请用心拜读!

本站提供经典的Excel公式函数实例,Word排版技巧,PPT教程;同时更兼有Flash,PowerPoint,数据库等技术文章。

//// <summary>
    ///  加水印文字
    /// </summary>
    /// <param name="picture">imge 对象</param>
    /// <param name="_watermarkText">水印文字内容</param>
    /// <param name="_watermarkPosition">水印位置</param>
    /// <param name="_width">被加水印图片的宽</param>
    /// <param name="_height">被加水印图片的高</param>
    private static void addWatermarkText(Graphics picture, string _watermarkText, string _watermarkPosition, int _width, int _height)
    {
        int[] sizes = new int[] { 16, 14, 12, 10, 8, 6, 4 };
        Font crFont = null;
        SizeF crSize = new SizeF();
        for (int i = 0; i < 7; i++)
        {
            crFont = new Font("arial", sizes[i], FontStyle.Bold);
            crSize = picture.MeasureString(_watermarkText, crFont);

            if ((ushort)crSize.Width < (ushort)_width)
                break;
        }

        float xpos = 0;
        float ypos = 0;

        switch (_watermarkPosition)
        {
            case "WM_TOP_LEFT":
                xpos = ((float)_width * (float).01) + (crSize.Width / 2);
                ypos = (float)_height * (float).01;
                break;
            case "WM_TOP_RIGHT":
                xpos = ((float)_width * (float).99) - (crSize.Width / 2);
                ypos = (float)_height * (float).01;
                break;
            case "WM_BOTTOM_RIGHT":
                xpos = ((float)_width * (float).99) - (crSize.Width / 2);
                ypos = ((float)_height * (float).99) - crSize.Height;
                break;
            case "WM_BOTTOM_LEFT":
                xpos = ((float)_width * (float).01) + (crSize.Width / 2);
                ypos = ((float)_height * (float).99) - crSize.Height;
                break;
            case "WM_BOTTOM_CENTER":
                xpos = ((float)_width / 2);
                ypos = ((float)_height * (float).99) - crSize.Height;
                break;
            case "WM_CENTER":
                xpos = ((float)_width / 2);
                ypos = ((float)_height / 2) - crSize.Height;
                break;
        }

        StringFormat StrFormat = new StringFormat();
        StrFormat.Alignment = StringAlignment.Center;

        SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(153, 0, 0, 0));
        picture.DrawString(_watermarkText, crFont, semiTransBrush2, xpos + 1, ypos + 1, StrFormat);

        SolidBrush semiTransBrush = new SolidBrush(Color.FromArgb(153, 255, 255, 255));
        picture.DrawString(_watermarkText, crFont, semiTransBrush, xpos, ypos, StrFormat);


        semiTransBrush2.Dispose();
        semiTransBrush.Dispose();
    }



上一篇:十一种Web网站程序性能测试工具介绍    下一篇:如何在网页之间隐藏传递的参数

会员评论列表:
针对本篇文章或本站,请您发表个人的建议或批评!
FreeBoxPc

谷歌搜索 百度搜索 本站仅与内容具备一定的实用价值的原创网站交换友情链接,力争为大众做出更优质的服务!
All Rights Reserved版权所有 本站备案信息:滇ICP备11001339号-2 站长联系方式 Email:dzwebs@126.com