Beispiel #1
0
        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(); }
        }