[C#]
[Serializable]
public delegate bool Image.GetThumbnailImageAbort();
可以 new 的吗?

解决方案 »

  1.   

    希望下面代码对你有用:/// <summary>
    /// 建立一个新的商品并上传商品图片和缩略图,如果数据库中已有该商品名,返回的布尔值为false。
    /// </summary>
    /// <param name="pI">商品信息</param>
    /// <param name="upFile">HtmlInputFile类对象</param>
    /// <param name="sitePhyAddr">文件目录的物理路径</param>
    public bool Create(ProductInfo pI, HtmlInputFile upFile, string sitePhyAddr)
    {
    // 得到文件后缀,并转换为小写
    string fileName = upFile.PostedFile.FileName;
    string fileFix = fileName.Substring(fileName.LastIndexOf('.') + 1);// 得到文件后缀
    fileFix = fileFix.ToLower();//转换为小写字符。
    int id = GetMaxId();
    string idNow; id++;
    idNow = id.ToString();
                
    // 判断用户是否选择了商品图
    if (fileName != "")
    {

    // 如果用户上传后缀合法则进行上传照片和缩略图
    if (fileFix == "jpg" || fileFix == "gif" )
    {
    // 上传照片原图
    string pathName = @"\Photo\" + idNow + "." + fileFix;
    string fullName = sitePhyAddr + pathName;
    string bPathName = @"\BreviaryPhoto\" + idNow + "." + fileFix;
    string bFullName = sitePhyAddr + bPathName; // 缩小图完整物理路径 upFile.PostedFile.SaveAs(fullName);
                    
    // 上传照片缩略图
    decimal width;
    decimal height;
    int newWidth;
    int newHeight; pathName = @"\Photo\" + idNow + "." + fileFix;
    System.Drawing.Image image = System.Drawing.Image.FromFile(fullName);
    System.Drawing.Image smallImage;
    width = image.Width;
    height = image.Height; // 如果图片宽大于高,则图片按预定宽度成比例缩放高度
    if (width > height)
    {
    newWidth = settings.ProductsBreviaryImageWidth;
    newHeight = (int) (height / width * newWidth);
    }
    else
    {
    // 否则图片按预定高度成比例缩放宽度
    newHeight = settings.ProductsBreviaryImageHeight;
    newWidth = (int) (width / height * newHeight);
    }

    try
    {
    smallImage = image.GetThumbnailImage(newWidth, newHeight, null, IntPtr.Zero);
    }
    catch(Exception ex)
    {
    image.Dispose();
    throw ex;
    } // 根据类型保存缩略图
    switch (fileFix)
    {
    case "jpg":
    smallImage.Save(bFullName,System.Drawing.Imaging.ImageFormat.Jpeg);
    break;
    case "gif":
    smallImage.Save(bFullName,System.Drawing.Imaging.ImageFormat.Gif);
    break;
    } smallImage.Dispose();
    image.Dispose();
    }
    else
    {
    throw new Exception("上传的图片后缀不合法");
    }
    }
    else
    {
    // 指向表示暂时没有商品的图片
    idNow = "0";
    fileFix = "gif";
    } // 数据库中创建商品
    DataLayer.Products prd = new DataLayer.Products(settings.SqlConnString);
    pI.PictureAddr = "Photo/" + idNow + "." + fileFix;
    pI.BreviaryPictureAddr = "BreviaryPhoto/" + idNow + "." + fileFix; return prd.Create(pI);
    }
      

  2.   

    呵呵,我不懂的说.
    看MSDN的例子说 public bool ThumbnailCallback(){return false;}public void Example_GetThumb(PaintEventArgs e){Image.GetThumbnailImageAbort myCallback =new Image.GetThumbnailImageAbort(ThumbnailCallback);Bitmap myBitmap = new Bitmap("Climber.jpg");Image myThumbnail = myBitmap.GetThumbnailImage(40, 40, myCallback, IntPtr.Zero);e.Graphics.DrawImage(myThumbnail, 150, 75);}
      

  3.   

    搂主,别的不说,我再98下,不能做实验测试一下,首先
    page_load里面的参数 EventArgs e和PaintEventArgs e是不一样的,后面的这一个可以这么e.Graphics引用,而前面的就不行了.
    这应该是一个问题,其他问题可能还存在,有些东西是不能直接由winform转移到webform得