当前位置导航:炫浪网>>网络学院>>网页制作>>ASP.NET教程

asp.net如何获取图片的分辨率

  public void formatImage()

  {

  //格式化后的图片大小

  int _WIDTH = 200;

  int _HEIGHT = 200;

  System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);

  System.Drawing.Image img1 = System.Drawing.Image.FromFile(@"d:\1.png");

  //制作缩略图

  int width = img1.Width;

  int height = img1.Height;

  double divide = (double)height / (double)width;

  if (width > _WIDTH || height > _HEIGHT)

  {

  if (width > _WIDTH)

  {

  height = Convert.ToInt16(Math.Floor(_WIDTH * divide));

  width = _WIDTH;

  }

  if (height > _HEIGHT)

  {

  width = Convert.ToInt16(Math.Floor(_HEIGHT / divide));

  height = _HEIGHT;

  }

  System.Drawing.Image timg = img1.GetThumbnailImage(width, height, myCallback, System.IntPtr.Zero);

  timg.Save(@"d:\2.jpg?http://www.xvna.com", System.Drawing.Imaging.ImageFormat.Jpeg);

  //下面的是保存到流中

  //MemoryStream ms = new MemoryStream();

  //timg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

  //ms.Close();

  }

  }

  public bool ThumbnailCallback()

  {

  return false;

  }

相关内容
赞助商链接