Loads a bitmap from file. - CSharp System.Drawing

CSharp examples for System.Drawing:Bitmap

Description

Loads a bitmap from file.

Demo Code


using System.IO;/*  www.j  a  va2 s. co  m*/
using System.Drawing;

public class Main{
        /// <summary>
        /// Loads a bitmap from file.
        /// </summary>
        public static Bitmap Load(string path, string filename)
        {
            try
            {
                if (!string.IsNullOrEmpty(filename))
                {
                    var fullPath = Path.Combine(path, filename);

                    if (File.Exists(fullPath))
                    {
                        return new Bitmap(Bitmap.FromFile(fullPath));
                    }
                }

                return null;
            }
            catch
            {
                return null;
            }
        }
}

Related Tutorials