日期:2014-05-18  浏览次数:20846 次

Bitmap 的应用问题
public partial class Public_WebUserControl_NewPicNoun : System.Web.UI.UserControl
{
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  int thumbnailWidth = 10, thumbnailHeight = 10;

  BMNounInsert TJCiTiao = new BMNounInsert();

  Bitmap fullPicture = null;
  ArrayList PicName = new ArrayList();

  ArrayList picList = TJCiTiao.NewPicNounInfo();

  if (picList.Count != 0)
  {
  for (int k = 0; k < picList.Count; k++)
  {
  string[] Pic = (string[])picList[k];

  PictureInfo picNouns = new PictureInfo();

  //picNouns.GID = new Guid (szClass[0]);
  picNouns.PName = Pic[1].ToString();

  fullPicture = new Bitmap(picNouns.PName);

  PicName.Add(picNouns);

  }
  }
  string PathToSave = "Public\\UploadWiKiPic\\";//图片的保存的地方
  Bitmap thumbnail = ResizeImage(fullPicture, thumbnailWidth, thumbnailHeight, ResizeOption.FixedWidthHeight);
  //thumbnail.Save(PathToSave + ThumbnailFilename, ImageFormat.Jpeg);

  Data_picList.DataSource = ??????????????怎么付给数据源
  Data_picList.DataBind();

  
  }

  }
 public enum ResizeOption
 {
 
  NoResize,

  FixedWidthHeight,

  MaintainAspectWidth,

  MaintainAspectHeight
 }
  private Bitmap ResizeImage(Bitmap original, int newWidth, int newHeight, ResizeOption option)
  {
  if (original.Width == 0 || original.Height == 0 || newWidth == 0 || newHeight == 0) return null;
  if (original.Width < newWidth) newWidth = original.Width;
  if (original.Height < newHeight) newHeight = original.Height;

  switch (option)
  {
  case ResizeOption.NoResize:
  newWidth = original.Width;
  newHeight = original.Height;
  break;
  case ResizeOption.FixedWidthHeight:
  break;
  case ResizeOption.MaintainAspectWidth:
  newHeight = (newWidth * original.Height / original.Width);
  break;
  case ResizeOption.MaintainAspectHeight:
  newWidth = (newHeight * original.Width / original.Height);
  break;
  }
  Bitmap newBitmap = new Bitmap(newWidth, newHeight);
  Graphics g = Graphics.FromImage(newBitmap);
  g.DrawImage(original, 0, 0, newWidth, newHeight);
  return newBitmap;
  }


}


------解决方案--------------------
把图片转换流的形式?