Newer
Older
Launcheroid / V3 / FImageLoad.cs
@Ivan Dominguez Ivan Dominguez 11 days ago 1 KB Lancheroid 3 to 4
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Launcheroid
{
    public partial class FImageLoad : Form
    {
        private FImageLoad()
        {
            InitializeComponent();
        }

        public static bool IsImage(string path)
        {
            try
            {
                using (Image i = Image.FromFile(path))
                    return true;
            }
            catch { };
            return false;
        }

        public static Image Open(string path)
        {
            try
            {
                return Image.FromFile(path);
            }
            catch
            {
                return null;
            }
        }

        public static Image Open()
        {
            string allim = "";
            string types = "";
            ImageCodecInfo[] decs = ImageCodecInfo.GetImageDecoders();
            foreach (ImageCodecInfo ici in decs)
            {
                types += "|" + ici.FormatDescription + " (" + ici.CodecName + ")" + "|" + ici.FilenameExtension;
                allim += ";" + ici.FilenameExtension;
            }
            types = "All images|" + allim.Substring(1) + types + "|All files|*.*";
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = types;
                if (ofd.ShowDialog() == DialogResult.OK)
                    return Open(ofd.FileName);
            }
            return null;
        }
    }
}