public static Region ConvertFromTransparentBitmap(UnsafeBitmap imageRegion, Color transparentColor) { // First we get the dimensions of our image GraphicsUnit aPixel = GraphicsUnit.Pixel; RectangleF imageBoundsF = imageRegion.GetBounds(ref aPixel); int imageWidth = Convert.ToInt32(imageBoundsF.Width); int imageHeight = Convert.ToInt32(imageBoundsF.Height); // This will be the path for our Region GraphicsPath regionPath = new GraphicsPath(); // We loop over every line in our image, and every pixel per line for (int intY = 0; intY < imageHeight; intY++) { for (int intX = 0; intX < imageWidth; intX++) { if (imageRegion.GetPixel(intX, intY) != transparentColor) { // We have to see this pixel! regionPath.AddRectangle(new Rectangle(intX, intY, 1, 1)); } } } Region formRegion = new Region(regionPath); regionPath.Dispose(); return(formRegion); } /* ConvertFromTransparentBitmap */
public static Point PixelSize(UnsafeBitmap bitmap) { GraphicsUnit unit = GraphicsUnit.Pixel; RectangleF bounds = bitmap.GetBounds(ref unit); return(new Point((int)bounds.Width, (int)bounds.Height)); }