Eto.Drawing.Bitmap.FromResource C# (CSharp) Method

FromResource() public static method

Loads a bitmap from the resource in the specified or caller's assembly
public static FromResource ( string resourceName, Assembly assembly = null ) : Bitmap
resourceName string Name of the resource in the caller's assembly to load
assembly System.Reflection.Assembly Assembly to load the resource from, or null to use the caller's assembly
return Bitmap
		public static Bitmap FromResource(string resourceName, Assembly assembly = null)
		{

			if (assembly == null)
			{
#if PCL
				if (TypeHelper.GetCallingAssembly == null)
					throw new ArgumentNullException("assembly", string.Format(CultureInfo.CurrentCulture, "This platform doesn't support Assembly.GetCallingAssembly(), so you must pass the assembly directly"));
				assembly = (Assembly)TypeHelper.GetCallingAssembly.Invoke(null, null);
#else
				assembly = Assembly.GetCallingAssembly();
#endif
			}

			using (var stream = assembly.GetManifestResourceStream(resourceName))
			{
				if (stream == null)
					throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Resource '{0}' not found in assembly '{1}'", resourceName, assembly.FullName));
				return new Bitmap(stream);
			}
		}

Same methods

Bitmap::FromResource ( string resourceName, Type type ) : Bitmap

Usage Example

Example #1
0
        Image LoadImage(NamespaceInfo ns)
        {
            var isIcon = IsIcon(ns.Namespace);

            if (isIcon)
            {
                return(Icon.FromResource(ns.Namespace, ns.Assembly));
            }
            return(Bitmap.FromResource(ns.Namespace, ns.Assembly));
        }