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);
}
}