/// <summary> /// 图片缓存 /// </summary> /// <param name="img"></param> /// <returns></returns> public string getImageCache(string img, Card card) { if (cfg.width <= 0 && cfg.height <= 0) { return(img); } string md5 = MyUtils.GetMD5HashFromFile(img); if (MyUtils.Md5isEmpty(md5) || cfg.imagecache == null) { //md5为空 return(img); } string file = MyPath.Combine(cfg.imagecache, md5); if (!File.Exists(file)) { //生成缓存 Bitmap bmp = MyBitmap.readImage(file); //缩放 if (card != null && card.IsType(CardType.TYPE_PENDULUM)) { bmp = MyBitmap.Zoom(bmp, cfg.pwidth, cfg.pheight); } else { bmp = MyBitmap.Zoom(bmp, cfg.width, cfg.height); } //保存文件 MyBitmap.SaveAsJPEG(bmp, file, 100); } return(img); }
//转换图片 public void ToImg(string img, string saveimg1, string saveimg2) { if (!File.Exists(img)) { return; } Bitmap bmp = new Bitmap(img); MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.W, imgSet.H), saveimg1, imgSet.quilty); MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.w, imgSet.h), saveimg2, imgSet.quilty); }
/// <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); }
//转换图片 //public void ToImg(string img, string saveimg1, string saveimg2) public void ToImg(string img, string saveimg1) { if (!File.Exists(img)) { return; } Bitmap bmp = new Bitmap(img); MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, this.imgSet.W, this.imgSet.H), saveimg1, this.imgSet.quilty); //MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.w, imgSet.h), // saveimg2, imgSet.quilty); bmp.Dispose(); }
//removed thumbnail #region 转换图片 public void ConvertImages(string imgpath, string gamepath, bool isreplace) { string picspath = MyPath.Combine(gamepath, "pics"); //string thubpath = MyPath.Combine(picspath, "thumbnail"); string[] files = Directory.GetFiles(imgpath); int i = 0; int count = files.Length; foreach (string f in files) { if (this.isCancel) { break; } i++; this.worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count)); string ex = Path.GetExtension(f).ToLower(); string name = Path.GetFileNameWithoutExtension(f); string jpg_b = MyPath.Combine(picspath, name + ".jpg"); //string jpg_s = MyPath.Combine(thubpath, name + ".jpg"); if (ex == ".jpg" || ex == ".png" || ex == ".bmp") { if (File.Exists(f)) { Bitmap bmp = new Bitmap(f); //大图,如果替换,或者不存在 if (isreplace || !File.Exists(jpg_b)) { MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, this.imgSet.W, this.imgSet.H), jpg_b, this.imgSet.quilty); } //小图,如果替换,或者不存在 //if (isreplace || !File.Exists(jpg_s)) //{ // MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.w, imgSet.h), // jpg_s, imgSet.quilty); //} } } } }