Open ez2X8pk61DHkdztgFT6O opened 2 years ago
As an afterthought: although the above code always 'runs', the transparency is only changed when the original image had an alpha channel to start with (not sure how your code handles this, maybe GDI+ automagically adds alpha?). Otherwise the alpha channel changes will do nothing as the 'unlockbits' will write back all data except the alpha channel values. To make things full-proof one would need to check whether the original image has an alpha channel. And if not, do something like this:
/// <summary>
/// Convert image to 32bpp argb. Disposes of the existing images!
/// </summary>
/// <param name="a"></param>
/// <returns></returns>
private Image ToARGB(Image a)
{
Bitmap clone = new Bitmap(a.Width, a.Height, PixelFormat.Format32bppPArgb);
using (Graphics gr = Graphics.FromImage(clone))
{
gr.DrawImage(a, new Rectangle(0, 0, clone.Width, clone.Height));
}
a.Dispose();
return clone;
}
Thank you! I will review it on weekend. Do you want to create a pull request for the changes?
Thanks for your code! I noticed that checking for image changes was the slowest part due to the use of GetPixel and SetPixel. The code below passes your tests and is much faster due to the use of 'LockBits' and direct access to the data. Requires the build properties to be set to 'allow unsafe code', though.
using System.Drawing;
namespace CMK { internal class ImageChangeAnalyser { private Bitmap oldImage = null;
}