A while ago I asked how to replace an image with a solid black colour whilst
preserving the alpha mask/channel, this was so that I could automatically
create a drop shadow. For future reference of anyone seeking the answer
here it is:
private static void MakeShadow(Bitmap dest)
{
BitmapData bits = dest.LockBits(new Rectangle(0, 0, dest.Width,
dest.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite,
System.Drawing.Imaging.PixelFormat.Format32bppArgb );
IntPtr bottomScanLine = bits.Scan0;
int bytesPerRow = bits.Width * 4;
unsafe
{
byte* pixelValue = (byte*)bottomScanLine.ToPointer();
for (int count = 0; count < bits.Width * bits.Height; count++ )
{
pixelValue[0] = 0;
pixelValue[1] = 0;
pixelValue[2] = 0;
pixelValue = pixelValue + 4;
}
}
dest.UnlockBits(bits);
}
My question is this. Is there a problem with me marking my assembly Unsafe?
It wont be used on a website or anything, only as part of an installed
desktop application.
Thanks
Pete