예제 #1
0
        /// <summary>
        /// 图片缓存
        /// </summary>
        /// <param name="img"></param>
        /// <param name="card"></param>
        /// <returns></returns>
        public string GetImageCache(string img, Card card)
        {
            if (!this.cfg.reimage)
            {
                //不需要调整
                return(img);
            }
            bool isPendulum = card.IsType(CardType.TYPE_PENDULUM);

            if (isPendulum)
            {
                if (this.cfg.pwidth <= 0 && this.cfg.pheight <= 0)
                {
                    return(img);
                }
            }
            else
            {
                if (this.cfg.width <= 0 && this.cfg.height <= 0)
                {
                    return(img);
                }
            }
            string md5 = MyUtils.GetMD5HashFromFile(img);

            if (MyUtils.Md5isEmpty(md5) || this.cfg.imagecache == null)
            {
                //md5为空
                return(img);
            }
            string file = MyPath.Combine(this.cfg.imagecache, md5);

            if (!File.Exists(file))
            {
                //生成缓存
                Bitmap bmp = MyBitmap.ReadImage(img);
                //缩放
                if (isPendulum)
                {
                    bmp = MyBitmap.Zoom(bmp, this.cfg.pwidth, this.cfg.pheight);
                }
                else
                {
                    bmp = MyBitmap.Zoom(bmp, this.cfg.width, this.cfg.height);
                }
                //保存文件
                MyBitmap.SaveAsJPEG(bmp, file, 100);
            }
            return(file);
        }