private unsafe void generate_alpha_mask(int cx, int cy) { alphaByteArray = new byte[cx * cy]; { #if USE_CLIPPING_ALPHA_MASK alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 20 * cx + 20, cx - 40, cy - 40, cx, 8, 1); #else alphaMaskImageBuffer.attach(alphaByteArray, (int)cx, (int)cy, cx, 1); #endif ImageBuffer image = new ImageBuffer(); image.Attach(alphaMaskImageBuffer, new blender_gray(1), 1, 0, 8); ImageClippingProxy clippingProxy = new ImageClippingProxy(image); ScanlineCachePacked8 sl = new ScanlineCachePacked8(); clippingProxy.clear(new ColorF(0)); VertexSource.Ellipse ellipseForMask = new MatterHackers.Agg.VertexSource.Ellipse(); System.Random randGenerator = new Random(1432); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); int i; int num = (int)numMasksSlider.Value; for (i = 0; i < num; i++) { if (i == num - 1) { ellipseForMask.init(Width / 2, Height / 2, 110, 110, 100); rasterizer.add_path(ellipseForMask); scanlineRenderer.RenderSolid(clippingProxy, rasterizer, sl, new Color(0, 0, 0, 255)); ellipseForMask.init(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100); rasterizer.add_path(ellipseForMask); scanlineRenderer.RenderSolid(clippingProxy, rasterizer, sl, new Color(255, 0, 0, 255)); } else { ellipseForMask.init(randGenerator.Next() % cx, randGenerator.Next() % cy, randGenerator.Next() % 100 + 20, randGenerator.Next() % 100 + 20, 100); // set the color to draw into the alpha channel. // there is not very much reason to set the alpha as you will get the amount of // transparency based on the color you draw. (you might want some type of different edeg effect but it will be minor). rasterizer.add_path(ellipseForMask); scanlineRenderer.RenderSolid(clippingProxy, rasterizer, sl, new Color((int)((float)i / (float)num * 255), 0, 0, 255)); } } alphaMaskImageBuffer.DettachBuffer(); } }