/// <summary> /// The resize code to make the preview fit in any control. /// </summary> /// <param name="nSize">The size available to the preview</param> private void ResizeVideo(Size nSize) { if (provider != null) { int x, y, w, h; float aspect = (float)imageWidth / imageHeight; float naspect = (float)nSize.Width / nSize.Height; if (aspect > naspect) { w = nSize.Width; h = (int)(w / aspect); x = 0; y = (nSize.Height - h) / 2; } else { h = nSize.Height; w = (int)(h * aspect); y = 0; x = (nSize.Width - w) / 2; } provider.ResizeVideo(x, y, w, h); } }