本帖最后由 zhpmy1 于 2009-11-03 21:09:20 编辑

解决方案 »

  1.   


    /// <summary>
        /// 在图片上加入图片版权信息
        /// </summary>
        /// <param name="strFileName">输入图片(绝对路径)</param>
        /// <param name="strOutfileName">输出图片(绝对路径)</param>
        /// <param name="strCopyRightFile">水印图片(绝对路径)</param>
        /// <param name="StrPlace">水印位置</param>
        /// <param name="bolFileName">是否删除输入图片</param>
        public static void CreateCopyRightImage(string strFileName, string strOutfileName, string strCopyRightFile, string StrPlace, bool bolFileName)
        {
            System.Drawing.Image MyImage = System.Drawing.Image.FromFile(strFileName);
            System.Drawing.Image CopyMyImage = System.Drawing.Image.FromFile(strCopyRightFile);
            System.Drawing.Bitmap OutPut = new System.Drawing.Bitmap(MyImage);
            System.Drawing.Graphics GImage = System.Drawing.Graphics.FromImage(OutPut);        int IntX = 0;
            int IntY = 0;
            if (StrPlace == "1")   // 在左上
            {
                IntX = 0;
                IntY = 0;
            }
            else if (StrPlace == "2")  // 在正上
            {
                IntX = (MyImage.Width - CopyMyImage.Width) / 2;
                IntY = 0;
            }
            else if (StrPlace == "3")  // 在右上
            {
                IntX = MyImage.Width - CopyMyImage.Width;
                IntY = 0;
            }
            else if (StrPlace == "4")  // 在正左
            {
                IntX = 0;
                IntY = (MyImage.Height - CopyMyImage.Height) / 2;
            }
            else if (StrPlace == "5")  // 在中间
            { //[Page]
                IntX = (MyImage.Width - CopyMyImage.Width) / 2;
                IntY = (MyImage.Height - CopyMyImage.Height) / 2;
            }
            else if (StrPlace == "6")  // 在正右
            {
                IntX = MyImage.Width - CopyMyImage.Width;
                IntY = (MyImage.Height - CopyMyImage.Height) / 2;
            }
            else if (StrPlace == "7")  // 在左下
            {
                IntX = 0;
                IntY = MyImage.Height - CopyMyImage.Height;
            }
            else if (StrPlace == "8")  // 在正下
            {
                IntX = (MyImage.Width - CopyMyImage.Width) / 2;
                IntY = MyImage.Height - CopyMyImage.Height;
            }
            else if (StrPlace == "9")  // 在右下
            {
                IntX = MyImage.Width - CopyMyImage.Width;
                IntY = MyImage.Height - CopyMyImage.Height;
            }
            else
            {
                IntX = MyImage.Width - CopyMyImage.Width - 10;
                IntY = MyImage.Height - CopyMyImage.Height - 10;
            }        // 画出水印的位置
            GImage.DrawImage(CopyMyImage, IntX, IntY, CopyMyImage.Width, CopyMyImage.Height);        string strExtend = strFileName.Substring(strFileName.LastIndexOf(".") + 1).ToLower();        switch (strExtend)
            {
                case "bmp":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Bmp);
                    break;
                case "jpg":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Jpeg);                break;
                case "gif":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Gif);
                    break;
                case "icon":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Icon); //[Page]
                    break;
                case "png":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Png);
                    break;
                case "tif":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Tiff);
                    break;
                default:
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;
            }        GImage.Dispose();
            OutPut.Dispose();
            MyImage.Dispose();
            CopyMyImage.Dispose();        if (bolFileName)
                File.Delete(strFileName);
        }
     这个方法调用就能生成水印图片,本地运行很好,但空间运行就不行了,也不报错
      

  2.   


    /// <summary>
        /// 在图片上加入图片版权信息
        /// </summary>
        /// <param name="strFileName">输入图片(绝对路径)</param>
        /// <param name="strOutfileName">输出图片(绝对路径)</param>
        /// <param name="strCopyRightFile">水印图片(绝对路径)</param>
        /// <param name="StrPlace">水印位置</param>
        /// <param name="bolFileName">是否删除输入图片</param>
        public static void CreateCopyRightImage(string strFileName, string strOutfileName, string strCopyRightFile, string StrPlace, bool bolFileName)
        {
            System.Drawing.Image MyImage = System.Drawing.Image.FromFile(strFileName);
            System.Drawing.Image CopyMyImage = System.Drawing.Image.FromFile(strCopyRightFile);
            System.Drawing.Bitmap OutPut = new System.Drawing.Bitmap(MyImage);
            System.Drawing.Graphics GImage = System.Drawing.Graphics.FromImage(OutPut);        int IntX = 0;
            int IntY = 0;
            if (StrPlace == "1")   // 在左上
            {
                IntX = 0;
                IntY = 0;
            }
            else if (StrPlace == "2")  // 在正上
            {
                IntX = (MyImage.Width - CopyMyImage.Width) / 2;
                IntY = 0;
            }
            else if (StrPlace == "3")  // 在右上
            {
                IntX = MyImage.Width - CopyMyImage.Width;
                IntY = 0;
            }
            else if (StrPlace == "4")  // 在正左
            {
                IntX = 0;
                IntY = (MyImage.Height - CopyMyImage.Height) / 2;
            }
            else if (StrPlace == "5")  // 在中间
            { //[Page]
                IntX = (MyImage.Width - CopyMyImage.Width) / 2;
                IntY = (MyImage.Height - CopyMyImage.Height) / 2;
            }
            else if (StrPlace == "6")  // 在正右
            {
                IntX = MyImage.Width - CopyMyImage.Width;
                IntY = (MyImage.Height - CopyMyImage.Height) / 2;
            }
            else if (StrPlace == "7")  // 在左下
            {
                IntX = 0;
                IntY = MyImage.Height - CopyMyImage.Height;
            }
            else if (StrPlace == "8")  // 在正下
            {
                IntX = (MyImage.Width - CopyMyImage.Width) / 2;
                IntY = MyImage.Height - CopyMyImage.Height;
            }
            else if (StrPlace == "9")  // 在右下
            {
                IntX = MyImage.Width - CopyMyImage.Width;
                IntY = MyImage.Height - CopyMyImage.Height;
            }
            else
            {
                IntX = MyImage.Width - CopyMyImage.Width - 10;
                IntY = MyImage.Height - CopyMyImage.Height - 10;
            }        // 画出水印的位置
            GImage.DrawImage(CopyMyImage, IntX, IntY, CopyMyImage.Width, CopyMyImage.Height);        string strExtend = strFileName.Substring(strFileName.LastIndexOf(".") + 1).ToLower();        switch (strExtend)
            {
                case "bmp":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Bmp);
                    break;
                case "jpg":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Jpeg);                break;
                case "gif":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Gif);
                    break;
                case "icon":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Icon); //[Page]
                    break;
                case "png":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Png);
                    break;
                case "tif":
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Tiff);
                    break;
                default:
                    OutPut.Save(strOutfileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;
            }        GImage.Dispose();
            OutPut.Dispose();
            MyImage.Dispose();
            CopyMyImage.Dispose();        if (bolFileName)
                File.Delete(strFileName);
        }
     这个方法调用就能生成水印图片,本地运行很好,但空间运行就不行了,也不报错
      

  3.   

    图片格式是什么。JPG是否都不行
    虚拟空间应该支持
      

  4.   

    gdi+绘图 功能不支持使用吧
    图片传到服务器上面 保存一次 然后 打完水印 再 保存一次