MonoMac.CoreGraphics.CGBitmapContext.ToImage C# (CSharp) Method

ToImage() public method

public ToImage ( ) : CGImage
return CGImage
        public CGImage ToImage()
        {
            return new CGImage (CGBitmapContextCreateImage (Handle), true);
        }

Usage Example

Ejemplo n.º 1
0
        private void DrawNoise(float opacity)
        {
            if (_noiseImageRef == null)
            {
                const int width = 124;
                const int height = width;
                const int size = width * height;

                var rgba = new byte[size];
                var random = new Random(120);
                for (var i = 0; i < size; i++)
                {
                    rgba[i] = (byte)(random.Next() % 256);
                }
                var colorSpace = CGColorSpace.CreateDeviceGray();
                var bitmapContext = new CGBitmapContext(rgba, width, height, 8, width, colorSpace, CGImageAlphaInfo.None);
                _noiseImageRef = bitmapContext.ToImage();
            }

            var context = NSGraphicsContext.CurrentContext.GraphicsPort;
            NSGraphicsContext.CurrentContext.SaveGraphicsState();
            context.SetAlpha(opacity);
            context.SetBlendMode(CGBlendMode.Screen);
            var scaleFactor = Window.BackingScaleFactor;
            context.ScaleCTM(1f / scaleFactor, 1f / scaleFactor);
            var imageRect = new RectangleF(PointF.Empty, new SizeF(_noiseImageRef.Width, _noiseImageRef.Height));
            context.DrawTiledImage(imageRect, _noiseImageRef);
            NSGraphicsContext.CurrentContext.RestoreGraphicsState();
        }