I've created small project for studying purpose using C#, to read PNG resource in a .dll assembly. Firstyly, I created a PNGResource.dll project embedded with "LargeIcon.png" and "SmallIcon.png". Access Modifier set to "Public".
Next, I created .exe project with a function like:
C#
privatestatic System.Drawing.Image ReadBitmapFromResource(string ResName, Assembly ResAssembly)
{
string ResFileName;
if (ResAssembly.FullName.IndexOf(',') > 0)
{
ResFileName = string.Format("{0}.Properties.Resources.resources", ResAssembly.FullName.Substring(0, ResAssembly.FullName.IndexOf(',')));
}
else
{
ResFileName = string.Format("{0}.Properties.Resources.resources", ResAssembly.FullName);
}
using (ResourceReader ResReader = new ResourceReader(ResAssembly.GetManifestResourceStream(ResFileName)))
{
string ResType;
byte[] ResByte;
ResReader.GetResourceData(ResName, out ResType, out ResByte);
if (ResType != null && ResByte != null ? ResType.IndexOf("System.Drawing.Bitmap") == 0 : false)
{
using (MemoryStream ResStream = new MemoryStream(ResByte))
{
return (Image)(new BinaryFormatter().Deserialize(ResStream));
}
}
}
returnnull;
}
Those images are successfully displayed, but with a slight incorrectly visual: transparent pixels displayed as white pixels. I've ensured those PNGs have transparent pixels with Photoshop. Something wrong with my code?
Answers
Know the answer? Post it. Somebody with the same question will find it here.
Answers
Know the answer? Post it. Somebody with the same question will find it here.