/// <summary> /// Swaps the channels for an image provided by a url. /// </summary> /// <param name="order">Channel ordering. Each value has to be [0..2] range.</param> /// <param name="imgUrl">Image url.</param> /// <returns>Processed image.</returns> public Bgr <byte>[,] SwapImageChannels(Uri imgUrl, int[] order) { if (order.Any(x => x < 0 || x > CHANNEL_COUNT - 1)) { throw new ArgumentException(String.Format("Each element of the channel order must be in: [{0}..{1}] range.", 0, CHANNEL_COUNT - 1)); } Bgr <byte>[,] image = null; try { image = imgUrl.GetBytes().DecodeAsColorImage(); } catch (Exception ex) { throw new Exception("The specified url does not point to a valid image.", ex); } image.Apply(c => swapChannels(c, order), inPlace: true); return(image); }