public static async void AllImageModify(string mainPath) { try { var allAdvertise = await Advertise.GetAllAsync(mainPath); if (allAdvertise?.Count > 0) foreach (var adv in allAdvertise) if (adv.Images?.Count > 0) foreach (var img in adv.Images) { var newPath = ImageManager.ModifyImage(img); //Path.Combine(Path.GetDirectoryName(img), Guid.NewGuid() + ".jpg"); if (File.Exists(newPath)) { File.Delete(img); } } } catch (Exception ex) { WebErrorLog.ErrorLogInstance.StartLog(ex); MessageBox.Show("ImageModifier:" + ex.Message); } }
private static List <string> GetNextImages(string advFullPath, int imgCount = 3) { var resultImages = new List <string>(); var monitor = new PerfMonitor(); try { if (string.IsNullOrEmpty(advFullPath)) { return(resultImages); } //گرفتن تمام عکسهای پوشه و فیلتر کردن عکسهای درست var picturesPath = Path.Combine(advFullPath, "Pictures"); var allImages = Utility.GetFiles(picturesPath, "*.jpg"); var selectedImages = new List <string>(); //حذف عکسهای زیر پیکسل 600*600 foreach (var imgItem in allImages) { var img = Image.FromFile(imgItem); if (img.Width < 600 || img.Height < 600) { try { img.Dispose(); File.Delete(imgItem); } catch { /**/ } } img.Dispose(); } allImages = Utility.GetFiles(picturesPath, "*.jpg"); if (allImages.Count <= imgCount) { selectedImages = allImages; } else { var indexes = new List <int>(); var rnd = new Random(); while (indexes.Count < imgCount) { var index = rnd.Next(allImages.Count); if (!indexes.Contains(index)) { indexes.Add(index); } } selectedImages.AddRange(indexes.Select(index => allImages[index])); } //ویرایش عکسها foreach (var img in selectedImages) { resultImages.Add(ImageManager.ModifyImage(img)); } return(resultImages); } catch (Exception ex) { WebErrorLog.ErrorLogInstance.StartLog(ex); // MessageBox.Show(@"GetNextImages:" + ex.Message); return(resultImages); } finally { monitor.Dispose(); } }