如何在C#中有没有像在php中的这种方法。<?php<br>function MyImg($imgfile) {<br>  $size = GetImageSize($imgfile);<br>  echo "<img src="$imgfile" $size[3]>";<br>}<br>MyImg("img/img1.gif");<br>MyImg("img/img2.png");<br>?><br>

解决方案 »

  1.   

    调用image类中的函数即可。
    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);
    }
      

  2.   

    public static System.Drawing.Image Set_Image_Size(double width,double height,System.Drawing.Image image)
    {
    double new_height;
    double new_width;
    double scale;
    new_height=height;
    new_width=width;
    if((image.Width>width)||(image.Height>height))
    {
    if(image.Width>width)
    {
    scale=image.Width/width;
    new_width=image.Width/scale;
    new_height=image.Height/scale;
    }
    else
    {
    scale=image.Height/height;
    new_width=image.Width/scale;
    new_height=image.Height/scale;
    }
    }
    System.Drawing.Image.GetThumbnailImageAbort myCallback =new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
    System.Drawing.Image myimage=image.GetThumbnailImage(Convert.ToInt32(new_width),Convert.ToInt32(new_height),myCallback,new System.IntPtr());
    image.Dispose();
    return myimage;
    }
    public static bool ThumbnailCallback()
    {
    return false;
    }