日期:2014-05-17  浏览次数:20823 次

C#图片以流的形式加水印 坐标改怎么设置。
用流读取的图片,我在上面加了文字水印。 但是我要怎么控制水印的位置,比如说我要加到右下角。应该怎么算坐标?(同一个坐标 。jpg格式跟tif格式位置不一样。)下面是我的代码:
/// 
/// 图片加水印
/// 
/// 图片路径
/// 字体
/// 字体大小
/// 水印位置
/// 水印文字
/// 存储图片的文件夹
public void AddWaterText(string oldPath,string font,int fontSize,string wntType,string Text,string directory)
{

            Byte[] photo = getImageByte(oldPath);
            MemoryStream stmBLOB = new MemoryStream(photo);
            Image pic = Image.FromStream(stmBLOB);

            Graphics grap = Graphics.FromImage(pic);
            Brush brush = new SolidBrush(Color.Red);//创建一把刷子
            int xpos = 10;
            int ypos = 10;
            switch (wntType)
            {
                case "WMP_Left_Top":
                    xpos = 10;
                    ypos = 10;
                    break;
                case "WMP_Right_Top":
                    xpos = pic.Width - 10;
                    ypos = 10;
                    break;
                case "WMP_Right_Bottom":
                    xpos = pic.Width - 10;
                    ypos = pic.Height - 10;
                    break;
                case "WMP_Left_Bottom":
                    xpos = 10;
                    ypos = pic.Height - 10;
                    break;
                case "WM_ZJ