I have a picture box, and import a .png picture into. Now when I rotate the actual image, the "free" space of the picture box, that does not include the image is filled by black pixels.
Q: How to make that black pixels transparent?
Edit:
Here is the rotation code
public static Bitmap RotateImage(Image image, PointF offset, float angle)
{
if (image == null)
{
return null;
}
try
{
Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using (Graphics g = Graphics.FromImage(rotatedBmp))
{
g.TranslateTransform(offset.X, offset.Y);
g.RotateTransform(angle);
g.TranslateTransform(-offset.X, -offset.Y);
g.DrawImage(image, new Point(0, 0));
}
return rotatedBmp;
}
catch (OutOfMemoryException)
{
GC.Collect();
}
catch (ArgumentException)
{
}
return image as Bitmap;
}
Here are original and modified images: