ismetertugral
7/31/2017 - 8:26 AM

Convert To PNG

Convert To PNG

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;

namespace ConvertToPNGG
{
    class Program
    {
        static void Main(string[] args)
        {

            //C:\Users\dedweb\Downloads
            Console.Write("Dosya yolunu giriniz : ");
            string pth = Console.ReadLine();
            Console.WriteLine();

            if (String.IsNullOrEmpty(pth))
                pth = "C:\\Users\\dedweb\\Downloads";

            string ext = ".jpeg,.jpg,.bmp";

            pth = pth.Trim();

            if (Directory.Exists(pth))
            {
                var directory = new DirectoryInfo(pth);
                //var allowedExtensions = new string[] { ".jpg", ".bmp" };
                var allowedExtensions = ext.Trim().Split(',');

                var imageFiles = from file in directory.EnumerateFiles("*", SearchOption.AllDirectories)
                                 where allowedExtensions.Contains(file.Extension.ToLower())
                                 select file;

                string savePth = pth + "\\ConvertedPNG";
                if (!Directory.Exists(savePth))
                    Directory.CreateDirectory(savePth);

                string nm = "";
                foreach (var file in imageFiles)
                {
                    var bitmap = Image.FromFile(file.FullName);
                    nm = Path.Combine(savePth, Path.GetFileNameWithoutExtension(file.Name) + ".png");
                    bitmap.Save(nm, ImageFormat.Png);
                    Console.WriteLine("Converting .. : " + file.Name);
                }



                Console.WriteLine("\nIslem tamamlandi. //////");
            }
            else
            {
                Console.WriteLine("\nDosya yolu bulunamadi ! ");
            }

            Console.WriteLine("\nCikmak icin bir tusa basiniz...");
            Console.ReadLine();

        }
    }
}
 static void Main(string[] args)
        {
            
            Console.Write("Kaynak yolunu giriniz : ");
            string pth = Console.ReadLine();
            Console.Write("Hedef yolunu giriniz : ");
            string destPth = Console.ReadLine();
            Console.WriteLine();
            pth = pth.Trim();
            destPth = destPth.Trim();
            if (File.Exists(pth))
            {
                Image image1 = Image.FromFile(pth);
                image1.Save(destPth, ImageFormat.Png);                           
                Console.WriteLine("\nIslem tamamlandi. //////");
            }
            else
            {
                Console.WriteLine("\nDosya yolu bulunamadi ! ");
            }

            Console.WriteLine("\nCikmak icin bir tusa basiniz...");
            Console.ReadLine();

        }