this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;

解决方案 »

  1.   

    System.Drawing.Image img;
    img = new System.Drawing.Image.FromFile(文件名);
    img.Hight = xx;
    img.Width = xx;pictureBox1.Image = img;
      

  2.   

    楼上的方法好象不行吧
    无法对属性或索引器“System.Drawing.Image.Width”赋值 -- 它是只读的
      

  3.   

    try:         Image img=Image.FromFile(@"g:\图片\ffx203.jpg");
    Bitmap bmp=new Bitmap(img,150,150);
    bmp.Save(@"c:\123.jpg")
      

  4.   

    楼主:
    读一下MSDN下关于picturebox类的说明比什么都强!
      

  5.   

    this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
    System.Drawing.Image img;
    img = new System.Drawing.Image.FromFile(文件名);
    img.Hight = xx;
    img.Width = xx;pictureBox1.Image = img;
      

  6.   

    我做了个函数:
    //*****************生成固定大小的缩略图***********************
    public string ToThumbnailImages(string nCompRootUrl,string sourceImagePath,int thumbnailImageWidth,int thumbnailImageHeight)
    {
    htmimes[".gif"]="image/gif";
    htmimes[".jpe"]="image/jpeg";
    htmimes[".jpeg"]="image/jpeg";
    htmimes[".jpg"]="image/jpeg";
    htmimes[".png"]="image/png";
    htmimes[".tif"]="image/tiff";
    htmimes[".tiff"]="image/tiff";
    htmimes[".bmp"]="image/bmp";

    string SourceImagePath = sourceImagePath;
    int ThumbnailImageWidth = thumbnailImageWidth;
    int ThumbnailImageHeight=thumbnailImageHeight;
    string sExt = SourceImagePath.Substring(SourceImagePath.LastIndexOf(".")).ToLower();
    string sSourceImageName = SourceImagePath.Substring(0,SourceImagePath.LastIndexOf(".")).ToLower();
    string sThumbnailImagePath=sSourceImageName+"_little"+sExt;
    if(SourceImagePath.ToString()==System.String.Empty) throw new NullReferenceException("SourceImagePath is null!");
    if(!CheckValidExt(sExt))
    {
    throw new ArgumentException("原图片文件格式不正确,支持的格式有[ "+ AllowExt +" ]","SourceImagePath");
    }
    //从 原图片 创建 Image 对象
    System.Drawing.Image image = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(SourceImagePath));
    int num = ((ThumbnailImageWidth / 4) * 3);
    int width = image.Width;
    int height = image.Height;
    //用指定的大小和格式初始化 Bitmap 类的新实例
    //Bitmap bitmap = new Bitmap(ThumbnailImageWidth, num, PixelFormat.Format32bppArgb);
    Bitmap bitmap = new Bitmap(image,ThumbnailImageWidth,ThumbnailImageHeight);
    //从指定的 Image 对象创建新 Graphics 对象
    Graphics graphics = Graphics.FromImage(bitmap);
    //清除整个绘图面并以透明背景色填充
    graphics.Clear(Color.Transparent);
    //在指定位置并且按指定大小绘制 原图片 对象
    //graphics.DrawImage(image, new Rectangle(0, 0, ThumbnailImageWidth, num));
    graphics.DrawImage(image, new Rectangle(0,0,ThumbnailImageWidth,ThumbnailImageHeight));
    image.Dispose();
    try
    {
    //将此 原图片 以指定格式并用指定的编解码参数保存到指定文件
    //string savepath = (ThumbnailImagePath==null?SourceImagePath:sThumbnailImagePath);
    string savepath = sThumbnailImagePath;
    SaveImage(bitmap,HttpContext.Current.Server.MapPath(savepath),GetCodecInfo((string)htmimes[sExt]));
    return savepath.ToString();

    }
    catch(System.Exception e)
    {
    throw e;
    }
    finally
    {
    bitmap.Dispose();
    graphics.Dispose();
    }
    }
      

  7.   

    void ThumbnailResize(string str_file, Size new_size)
       {
          Image src_image = Image.FromFile(str_file);
          Image dst_image = src_image.GetThumbnailImage(new_size.Width, 
             new_size.Height, null, System.IntPtr.Zero);
          dst_image.Save("tn-" + str_file, 
             System.Drawing.Imaging.ImageFormat.Jpeg);
          dst_image.Dispose();
          src_image.Dispose();
       }   ThumbnailResize("aikido.jpg", new Size(655, 480));