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;
        }

 

posted @ 2022-03-08 14:03  韩梦芫  阅读(212)  评论(0编辑  收藏  举报