예제 #1
0
        public static void Run()
        {
            float fontSize = 36.0f;
            //Font font = new Font("Arabic Typesetting", fontSize);
            string basePath = @"C:\Users\KESKIN\Desktop\cevsen\out\";
            Font font = new Font("Scheherazade", fontSize);
            var brush1 = new SolidBrush(Color.FromArgb(85, 0, 0));
            var brush2 = new SolidBrush(Color.FromArgb(0, 85, 0));
            var cuz = 0;

            /*
            foreach (var item in Kuran.kuran)
            {
                var cuzIndex = Kuran.cuzler.IndexOf(s => s == item.Key);
                if (cuzIndex > -1) cuz = cuzIndex + 1;
                if (!Directory.Exists(basePath + cuz)) Directory.CreateDirectory(basePath + cuz);

                using (Bitmap a = new Bitmap(5000, (int)(fontSize + fontSize)))
                {
                    using (Graphics g = Graphics.FromImage(a))
                    {
                        for (int i = 0; i < item.Value.Length; i++)
                        {
                            if (File.Exists(basePath + cuz + "\\" + item.Key + "_" + i + ".png")) continue;
                            SizeF size = g.MeasureString(item.Value[i], font);
                            g.TextRenderingHint = TextRenderingHint.AntiAlias;
                            g.Clear(Color.Transparent);
                            g.DrawString(item.Value[i], font, i%2==0?brush1:brush2, new PointF(0, fontSize / 7f)); // requires font, brush etc
                            Bitmap b = (Bitmap)a.CropImage(0, 0, (int)size.Width, (int)size.Height, false);
                            b.SavePng(basePath + cuz + "\\" + item.Key + "_" + i + ".png");
                        }
                    }
                }
                Console.WriteLine(item.Key);
                //if(ayetNo==10) break;
            }
             */

            Dictionary<string, string[]> cevsen = CevsenFromFileToCode.Run();

            using (Bitmap a = new Bitmap(5000, (int)(fontSize + fontSize)))
            {
                using (Graphics g = Graphics.FromImage(a))
                {
                    foreach (var item in cevsen) // new Dictionary<string, string[]> { { "subhan_hamd_0", new String[] { "سُبْحاَنَ", "اللَّهِ", "وَ", "الْحَمْدُ", "لِلَّهِ", "وَ", "لَا", "اِلَهَ", "اِلَّا", "اللَّهُ", "وَاللَّهُ", "اَكْبَرُ", "وَ", "لَا", "حَوْلَ", "وَ", "لَا", "قُوَّةَ", "اِلَّا", "بِاللَّهِ", "الْعَلِىِّ", "الْعَظِيمِ", } } }
                        for (int i = 0; i < item.Value.Length; i++)
                        {
                            SizeF size = g.MeasureString(item.Value[i], font);
                            g.TextRenderingHint = TextRenderingHint.AntiAlias;
                            g.Clear(Color.Transparent);
                            g.DrawString(item.Value[i], font, i % 2 == 0 ? brush1 : brush2, new PointF(0, fontSize / 7f)); // requires font, brush etc
                            Bitmap b = (Bitmap)a.CropImage(0, 0, (int)size.Width, (int)size.Height, false);
                            b.SavePng(basePath + item.Key + "_" + i + ".png");
                        }
                }
            }
        }
예제 #2
0
        public void TestCropImageToMaximumDimension()
        {
            using (var image = new Bitmap(ImageLocation))
            {
                var resizedImage = image.CropImage(90);

                Assert.AreEqual(90, resizedImage.Width);

                resizedImage.Dispose();
            }
        }
예제 #3
0
        public void TestCropImage()
        {
            using (var image = new Bitmap(ImageLocation))
            {
                var resizedImage = image.CropImage(320, 200);

                Assert.AreEqual(320, resizedImage.Width);
                Assert.AreEqual(200, resizedImage.Height);

                resizedImage.Dispose();
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            var paramsControl = new ParamsControl<CommandLineParamsOptions>(new CommandLineParamsOptions(), args, "Thumbnail extractor");
            var valid = paramsControl.Validate();
            if (valid == false)
            {
                Console.WriteLine(paramsControl.GenerateError());
                return;
            }
            FileAttributes sourceAttributes = FileAttributes.Normal;
            try
            {
                sourceAttributes = File.GetAttributes(paramsControl.Values.Source);
            }
            catch(Exception ex)
            {
                Console.WriteLine("Failed to get the file: " + ex.ToString());
                return;
            }
            IEnumerable<string> videosToProcess = null;
            if(sourceAttributes.HasFlag(FileAttributes.Directory))
            {
                videosToProcess = Directory.GetFiles(paramsControl.Values.Source, "*m.mp4", SearchOption.AllDirectories);
            }
            else
            {
                videosToProcess = new string [] { paramsControl.Values.Source };
            }
            foreach(var videoPath in videosToProcess)
            {
                string rawOutFile = ExtractFrameToFile(paramsControl, videoPath);
                if (File.Exists(rawOutFile))
                {
                    var outFile = GetThumbName(rawOutFile, "play_", ".jpg");
                    Bitmap raw = new Bitmap(rawOutFile);
                    raw.CropImage()
                        .FilterEdge()
                        //.ToBlackAndWhite()
                        .Negative()
                        .Resize(paramsControl.Values.HeightOfTheOutputInPixels)
                        .AddPlayOverlay()
                        .Save(outFile);
                }
            }

            Console.WriteLine("Done");
        }