dll 类代码        /// 缩略图
         public static byte[] GetThumbnail(byte[] img, int width, int height, string mode)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream(img);
            Image originalImage = System.Drawing.Image.FromStream(ms);            int towidth = width;
            int toheight = height;            int x = 0;
            int y = 0;
            int ow = originalImage.Width;
            int oh = originalImage.Height;
            Image bitmap;
            if (ow > towidth || oh > toheight)
            {
                switch (mode)
                {
                    case "HW"://指定高宽缩放(可能变形)                
                        break;
                    case "W"://指定宽,高按比例                    
                        toheight = originalImage.Height * width / originalImage.Width;
                        break;
                    case "H"://指定高,宽按比例
                        towidth = originalImage.Width * height / originalImage.Height;
                        break;
                    case "Cut"://指定高宽裁减(不变形)                
                        if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                        {
                            oh = originalImage.Height;
                            ow = originalImage.Height * towidth / toheight;
                            y = 0;
                            x = (originalImage.Width - ow) / 2;
                        }
                        else
                        {
                            ow = originalImage.Width;
                            oh = originalImage.Width * height / towidth;
                            x = 0;
                            y = (originalImage.Height - oh) / 2;
                        }
                        break;
                    default:
                        break;
                }                //新建一个bmp图片
                bitmap = new System.Drawing.Bitmap(towidth, toheight);                //新建一个画板
                Graphics g = System.Drawing.Graphics.FromImage(bitmap);                //设置高质量插值法
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;                //设置高质量,低速度呈现平滑程度
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;                //清空画布并以透明背景色填充
                g.Clear(Color.Transparent);                //在指定位置并且按指定大小绘制原图片的指定部分
                g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight),
                    new Rectangle(x, y, ow, oh),
                    GraphicsUnit.Pixel);
            }
            else
                bitmap = originalImage;           // Image aa = System.Drawing.Image.FromFile("c:\\aa.bmp");            Bitmap bb = new Bitmap(bitmap);
            System.IO.MemoryStream stream1 = new System.IO.MemoryStream();
            bb.Save(stream1, System.Drawing.Imaging.ImageFormat.Bmp);
            Byte[] nn = stream1.ToArray();  
            return nn;
        }

a.asp
------------------------------------------------
sqlstr = "Select P_Image From Product where Product_Id=1"
Set prs = Cdb.Getrs(sqlstr,1)
m_pic = prs.Fields("P_Image").value
Set rs = server.CreateObject("ClassLibrary.CL") Response.ContentType = "image/gif" 
Response.BinaryWrite (rs.GetThumbnail(m_pic,20,20,"HW"))
其它注册都正常.
运行a.asp时
对象不支持此属性或方法: 'rs.GetThumbnail'
我知道是类型不对应而造成的,请求各位大虾们应如何修改.谢谢.

解决方案 »

  1.   

    网上找的资料第一种方法:c#专门用于.NET运行时,其程序是受管制的代码.
    不过可以后期绑定C#装配件,即.DLL代码,但很麻烦.
    1.先sn -k yourdll.snk 创建全局高速缓存;
    2.修改你的assemblyinfo.cs:
    using system.reflection
    [assembly:AssemblyKeyFile:("yourdll.snk")]
    3.编译assemblyinfo.cs模块
    csc /t:module /out:assembleinfo.dll assemblyinfo.cs
    4.再编译yourdll.cs,将其安装到全局高速缓存中
    csc /t:library /addmodule:assemblyinfo.dll yourdll.cs
    gacutil /i yourdll.dll
    最后可以在VB中应用
    set objtemp=createobject("yourdll.yourdll")
    地二种方法:ASP调用C# DLL 
    ASP 调用C#编写的DLL的方法        前一阵子一直在忙一个项目,其中要用到ASP调用C#的DLL,网上资历料不少,总结了一下,写个例子出来         首先建立一个类库的项目
     之后编写一个接口,ASP要调用的对象实现这个接口,代码如下(要有一个没有参数的构造函数)  using System;
    using System.Runtime.InteropServices;namespace Test
    {
        [Guid("123AC4E1-BEB0-45a1-BE3F-91BDD16A117A")]
        public interface ITest
        {
            [DispId(0)]
            string TestString();
        }        public class Test : ITest
        {
                                    //从工具下的创建GUID取得
            public Test()
            {
            }        #region ITest 成员        public string TestString()
            {
                return "Test";
            }        #endregion
        }
             之后对这个类进行强签名(如果这个DLL调用的其它DLL的话,也要进行强签名),运行Visual Studio 2003 .net 命令提示,执行sn -k 后加输出的DLL所在目录,如sn -k 文件路径\test.snk,之后会生成test.SNK文件,打开AssemblyInfo.cs文件,在[assembly: AssemblyKeyFile("")]里填写生成的SNK文件的路径,如[assembly: AssemblyKeyFile("文件路径\\test.snk")],之后重新编译
     
        
            使用regasm工具对程序集进行注册,运行Visual Studio 2003 .net 命令提示,执行regasm /tlb DLL文件
              
            之后使用gacutil工具将DLL程序集安装到全局程序集缓存中,也是先运行Visual Studio 2003 .net 命令提示,再执行gacutil /i 要注册的DLL的路径  
             之后就可以asp里调用测试啦
             sn.exe 
             regasm.exe
             gacutil.exe
             这三个工具都可以在Visual Studio .net 2003的安装目录下的SDK\v1.1\Bin目录下找到
      

  2.   

    是要生成缩略图?看我这个
    public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
        {
            System.Drawing.Image originalImage = System.Drawing.Image.FromFile(originalImagePath);        int towidth = width;
            int toheight = height;        int x = 0;
            int y = 0;
            int ow = originalImage.Width;
            int oh = originalImage.Height;        switch (mode)
            {
                case "HW"://指定高宽缩放(可能变形)                
                    break;
                case "W"://指定宽,高按比例                    
                    toheight = originalImage.Height * width / originalImage.Width;
                    break;
                case "H"://指定高,宽按比例
                    towidth = originalImage.Width * height / originalImage.Height;
                    break;
                case "Cut"://指定高宽裁减(不变形)                
                    if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                    {
                        oh = originalImage.Height;
                        ow = originalImage.Height * towidth / toheight;
                        y = 0;
                        x = (originalImage.Width - ow) / 2;
                    }
                    else
                    {
                        ow = originalImage.Width;
                        oh = originalImage.Width * height / towidth;
                        x = 0;
                        y = (originalImage.Height - oh) / 2;
                    }
                    break;
                default:
                    break;
            }        //新建一个bmp图片
            System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);        //新建一个画板
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);        //设置高质量插值法
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;        //设置高质量,低速度呈现平滑程度
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;        //清空画布并以透明背景色填充
            g.Clear(System.Drawing.Color.Transparent);        //在指定位置并且按指定大小绘制原图片的指定部分
            g.DrawImage(originalImage, new System.Drawing.Rectangle(0, 0, towidth, toheight),
                new System.Drawing.Rectangle(x, y, ow, oh),
                System.Drawing.GraphicsUnit.Pixel);        try
            {
                //以jpg格式保存缩略图
                bitmap.Save(thumbnailPath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (System.Exception e)
            {
                throw e;
            }
            finally
            {
                originalImage.Dispose();
                bitmap.Dispose();
                g.Dispose();
            }
        }
      

  3.   

    好像各位没理解我哦,我不是指asp 如何调用dll 这个我已经成功了,我是指,如何把 asp 的图片类型,我是把图片放到数据库 的,读出来是二进制,然后放到dll  里进行缩略处理,在类型上出错了,应该如何处理?:)
      

  4.   

    这个基本没办法
    只能换一种思路了,你先不要使用asp来调用先用asp.net来调用,新建一个解决方案把你dll那个工程包含进来,在建立另一个asp.net工程,在asp.net引用com控件来引用dll,然后启动调试,这样如果有错误,vs2005至少有错误的详细信息,有错误的详细信息你才有可能知道是那里错了
      

  5.   

    呵呵,大家别看代码,那代码只是一个缩略图功能,我只是想能否直接生成dll 让 asp 来调用, 过去都用vb 组件这些,现在只想用自己的,而且用 c#写,
      

  6.   

    你怎么用
    static
    方法
    改!!!!!!
      

  7.   

    com
    是基于接口调用的不能用static