oriImg.Save(filePath,Enum.Parse(System.Drawing.Imaging.ImageFormat,imgType));

解决方案 »

  1.   

    急急, 我的程序中大量用switch(imageType)
    // {
    // case "image/pjpeg":这种判断, 程式实在是太肥, 能否减减肥!!!
      

  2.   

    谢谢旗娃 大哥: 但还是出错啊?oriImg.Save(filePath,Enum.Parse(System.Drawing.Imaging.ImageFormat,imageType));
    编译时出错: D:\MyProject\ElecTrade\Web\Components\uploadFile.cs(218): “System.Drawing.Imaging.ImageFormat”表示“类”,此处应为“变量”
      

  3.   

    这样编译不错: oriImg.Save(filePath,(System.Drawing.Imaging.ImageFormat)Enum.Parse(typeof(System.Drawing.Imaging.ImageFormat),imageType));但是上载文件时又出错:
    --------------------------------------------------------------------------
    ex.ToString() "System.ArgumentException: 提供的类型必须是 Enum。
    参数名:enumType
       at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
       at System.Enum.Parse(Type enumType, String value)
       at ElecTrade.Components.UpLoadFile.SaveImage(HttpPostedFile postedFile, String imageType, String filePath) in d:\myproject\electrade\web\components\uploadfile.cs:line 218" string
    ;