1. 程式人生 > 其它 >c# 判斷是否破圖

c# 判斷是否破圖

  //GDAL影象初始化
            GdalConfiguration.ConfigureGdal();
            GdalConfiguration.ConfigureOgr();
            Gdal.AllRegister();
            //設定中文字元預設
            Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
            Gdal.SetConfigOption("SHAPE_ENCODING", "");

呼叫:

/// <summary>
/// 判斷圖片是否損壞 /// </summary> /// <param name="path">圖片路徑</param> /// <returns>true/false</returns> public static bool IsDamagePhoto(string path) { bool result = false; try { var dataset = Gdal.Open(path, Access.GA_ReadOnly);
//當讀取出集合為空,則表示圖片破損 if (dataset == null) { result = true; } } catch (Exception ex) { LogHelper.WriteInfoLog("讀取圖片異常:" + ex.Message + ";" + ex.StackTrace); return true; }
return result; }