using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace Studio
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
System.Drawing.Image image; 
System.Drawing.Image aNewImage; 
System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); 
int width; 
int height; 
int newwidth; 
int newheight; 
image = System.Drawing.Image.FromFile(Server.MapPath("classpic/" + "rs1.gif")); 
width = image.Width; 
height = image.Height; 
if (width > height) 

newwidth = 110; 
newheight = image.Height / image.Width * newwidth; 

else 

newheight = 110; 
newwidth = image.Width / image.Height * newheight; 

aNewImage = image.GetThumbnailImage(newwidth, newheight, callb, new System.IntPtr()); 
aNewImage.Save(Server.MapPath("smallpic/" + "rs1.gif")); 
image.Dispose();  } public bool ThumbnailCallback()
{
return false;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}
错误是:
行 39:  newwidth = image.Width / image.Height * newheight; 
行 40:  } 
行 41:  aNewImage = image.GetThumbnailImage(newwidth, newheight, callb, new System.IntPtr()); 
行 42:  aNewImage.Save(Server.MapPath("smallpic/" + "rs1.gif")); 
行 43:  image.Dispose();

解决方案 »

  1.   

    http://sz.luohuedu.net/xml/ShowDetail.asp?id=45E7E33C-F149-450E-B5D5-832958C20538提供参考。
      

  2.   

    这个是VB的,
    http://sz.luohuedu.net/xml/ShowDetail.asp?id=45E7E33C-F149-450E-B5D5-832958C20538上面的代码是从VB转过来的,VB的代码是可以执行的。
    就是转成C#以后出错了:(
      

  3.   

    出现上面错误是因为你计算新图片的长和宽的时候错误,出现了newwidth 或者 newheight 为0的情况,还有保存的时候要加上参数 System.Drawing.Imaging.ImageFormat.Gif 否则可能生成的图片没法显示trySystem.Drawing.Image image; 
    System.Drawing.Image aNewImage; 
    System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); 
    int width; 
    int height; 
    int newwidth = 110; 
    int newheight = 110; 
    image = System.Drawing.Image.FromFile(Server.MapPath("classpic/" + "rs1.gif")); 
    width = image.Width; 
    height = image.Height; 
    if (width < height) 

    //newheight = (int) image.Height/image.Width * newwidth; 
    newheight = (int) ( height/(width/newwidth) );

    else 

    //newheight = 110; 
    //newwidth = (int)image.Width/image.Height*newheight; 
    newheight = (int) (width/(height/newheight));

    aNewImage = image.GetThumbnailImage(newwidth, newheight, callb, new System.IntPtr()); 
    aNewImage.Save(Server.MapPath("smallpic/" + "rs1.gif"),System.Drawing.Imaging.ImageFormat.Gif); 
    image.Dispose();
      

  4.   

    成功了~~太感谢你了,LaoDai_Net(『老代.Net』。已经会更努力地学习.net。再次谢谢:)