コード例 #1
0
        public static SnapshotAnchor Create(ARSCNView capturingView)
        {
            try
            {
                var frame   = capturingView.Session?.CurrentFrame;
                var camera  = frame?.Camera;
                var capture = frame?.CapturedImage;

                if (frame == null || camera == null || capture == null)
                {
                    return(null);
                }

                var image = CIImage.FromImageBuffer(capture);

                var orientation = OrientationUtility.CreateFromDeviceOrientation(UIDevice.CurrentDevice.Orientation);

                var context = new CIContext(new CIContextOptions {
                    UseSoftwareRenderer = false
                });

                var data = context.GetJpegRepresentation(image.CreateByApplyingOrientation(orientation)
                                                         , CGColorSpace.CreateDeviceRGB()
                                                         , new CIImageRepresentationOptions {
                    LossyCompressionQuality = 0.7f
                });

                return(new SnapshotAnchor(data, camera.Transform));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to create image: " + ex.Message);
                return(null);
            }
        }