当前位置: 代码迷 >> ASP.NET >> 静态方法里可以调用类吗?解决思路
  详细解决方案

静态方法里可以调用类吗?解决思路

热度:5139   发布时间:2013-02-25 00:00:00.0
静态方法里可以调用类吗?
各位大侠,我在研究一个上传多个图片加水印的功能,现在上传多个文件已经成功了,用的是uploadify,他在后台只有一个方法,我想在这里面写,关于给图片增加水印的功能代码如下:
C# code
[System.Web.Services.WebMethod]        public static void GetSound(string aa, string type)        {            try            {                string webFilePath = "";                string webFilePath_sy = "";                                AddWater(webFilePath, webFilePath_sy);            }            catch            {            }        }

增加水印的类如下:
C# code
/// <summary>        /// 在图片上增加文字水印        /// </summary>        /// <param name="Path">原服务器图片路径</param>        /// <param name="Path_sy">生成的带文字水印的图片路径</param>        public void AddWater(string Path, string Path_sy)        {            string addText = "111111111111111111111";                        System.Drawing.Image image = System.Drawing.Image.FromFile(Path);            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);            g.DrawImage(image, 0, 0, image.Width, image.Height);            System.Drawing.Font f = new System.Drawing.Font("Verdana", 60);            System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Green);            g.DrawString(addText, f, b, 35, 35);            g.Dispose();            image.Save(Path_sy);            image.Dispose();        }


我应该怎么调用这个类,给图片加水印呢

------解决方案--------------------------------------------------------
new someclass().AddWater(webFilePath, webFilePath_sy);

------解决方案--------------------------------------------------------
假设AddWater属于一个叫someclass的类,并且构造函数为无参数。
------解决方案--------------------------------------------------------
静态方法中同样可以创建类实例,或者直接用其他static类的public方法
------解决方案--------------------------------------------------------
顶楼上!
------解决方案--------------------------------------------------------
无聊,楼上正解
------解决方案--------------------------------------------------------
把类实例化后不就能调用了
------解决方案--------------------------------------------------------
Main方法就是静态的,不也什么对象都可以用吗。。。
  相关解决方案