protected virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             _context.Dispose();
         }
     }
     this.disposed = true;
 }
Ejemplo n.º 2
0
 protected override void Dispose(bool disposing)
 {
     if (disposed)
     {
         return;
     }
     disposed = true;
     if (context != null)
     {
         context.Dispose();
     }
     base.Dispose(disposing);
 }
Ejemplo n.º 3
0
        unsafe void UpdateBackground(ARFrame frame)
        {
            using (var img = frame.CapturedImage)
            {
                using (var ciImage = CIImage.FromImageBuffer(img))
                {
                    using (var rotatedImage = ciImage.CreateByApplyingOrientation(ImageIO.CGImagePropertyOrientation.Right))
                    {
                        var size = new CGSize(rotatedImage.Extent.Size);

                        using (var rotatedBuff = new CVPixelBuffer((nint)size.Width,
                                                                   (nint)size.Height, img.PixelFormatType))
                        {
                            var _coreImageContext = new CIContext(null);

                            rotatedBuff.Lock(CVPixelBufferLock.None);

                            _coreImageContext.Render(rotatedImage, rotatedBuff);

                            var yPtr  = rotatedBuff.BaseAddress;
                            var uvPtr = rotatedBuff.GetBaseAddress(1);

                            if (yPtr == IntPtr.Zero || uvPtr == IntPtr.Zero)
                            {
                                return;
                            }

                            int wY  = (int)rotatedBuff.Width;
                            int hY  = (int)rotatedBuff.Height;
                            int wUv = (int)rotatedBuff.GetWidthOfPlane(1);
                            int hUv = (int)rotatedBuff.GetHeightOfPlane(1);

                            cameraYtexture.SetData(0, 0, 0, wY, hY, (void *)yPtr);
                            cameraUVtexture.SetData(0, 0, 0, wUv, hUv, (void *)uvPtr);

                            rotatedBuff.Unlock(CVPixelBufferLock.None);

                            _coreImageContext.Dispose();
                        }
                    }
                }
            }
        }