/// <summary> /// Creates a trackbar and attaches it to the window. /// </summary> /// <param name="trackbarName">Name of the created trackbar.</param> /// <param name="value">A reference to an integer value that specifies the position of the slider.</param> /// <param name="count">Maximal position of the slider. Minimal position is always 0.</param> /// <param name="onChanged"> /// The callback method that will be called every time the slider changes position. /// </param> public void CreateTrackbar(string trackbarName, ref int value, int count, TrackbarCallback onChanged = null) { if (trackbars == null) { trackbars = new List <TrackbarCallback>(); } if (onChanged != null) { trackbars.Add(onChanged); } NativeMethods.cvCreateTrackbar(trackbarName, name, ref value, count, onChanged); }
/// <summary> /// ウィンドウにトラックバーを作成し、作成したトラックバーを返す /// </summary> /// <param name="name">トラックバーの名前</param> /// <param name="value">スライダの初期位置</param> /// <param name="count">スライダの最大値.最小値は常に 0.</param> /// <param name="onChange">スライダの位置が変更されるたびに呼び出されるデリゲート</param> /// <returns></returns> #else /// <summary> /// Creates the trackbar and attaches it to this window /// </summary> /// <param name="name">Name of created trackbar. </param> /// <param name="value">The position of the slider</param> /// <param name="count">Maximal position of the slider. Minimal position is always 0. </param> /// <param name="onChange">the function to be called every time the slider changes the position. This function should be prototyped as void Foo(int);</param> /// <returns></returns> #endif public TrackbarWithLabel CreateTrackbar(string name, int value, int count, TrackbarCallback onChange) { var t = new TrackbarWithLabel(name, value, count, 0); t.Dock = DockStyle.Top; t.Trackbar.ValueChanged += (o, e) => { int pos = ((TrackBar)o).Value; onChange(pos); }; SetClientSize(new System.Drawing.Size(ClientSize.Width, ClientSize.Height + t.Height)); _panelTrackbar.Height += t.Height; _panelTrackbar.Controls.Add(t); return(t); }
/// <summary> /// 初期化 /// </summary> /// <param name="name">トラックバーの名前</param> /// <param name="window">トラックバーの親ウィンドウ名</param> /// <param name="value">スライダの初期位置</param> /// <param name="max">スライダの最大値.最小値は常に 0.</param> /// <param name="callback">スライダの位置が変更されるたびに呼び出されるデリゲート</param> #else /// <summary> /// Constructor /// </summary> /// <param name="trackbarName">Trackbar name</param> /// <param name="windowName">Window name</param> /// <param name="initialPos">Initial slider position</param> /// <param name="max">The upper limit of the range this trackbar is working with. </param> /// <param name="callback">Callback handler</param> #endif internal CvTrackbar(string trackbarName, string windowName, int initialPos, int max, TrackbarCallback callback) { if (string.IsNullOrEmpty(trackbarName)) { throw new ArgumentNullException(nameof(trackbarName)); } if (string.IsNullOrEmpty(windowName)) { throw new ArgumentNullException(nameof(windowName)); } this.callback = callback ?? throw new ArgumentNullException(nameof(callback)); TrackbarName = trackbarName; WindowName = windowName; // userData wrapper callbackNative = (pos, ud) => callback(pos); gchCallback = GCHandle.Alloc(callback); gchCallbackNative = GCHandle.Alloc(callbackNative); var callbackPtr = Marshal.GetFunctionPointerForDelegate(callbackNative); NativeMethods.HandleException( NativeMethods.highgui_createTrackbar( trackbarName, windowName, IntPtr.Zero, max, callbackPtr, IntPtr.Zero, out result)); // Set initial trackbar position NativeMethods.HandleException( NativeMethods.highgui_setTrackbarPos( trackbarName, windowName, initialPos)); if (result == 0) { throw new OpenCvSharpException("Failed to create CvTrackbar."); } }
/// <summary> /// 初期化(目盛りは0~100) /// </summary> /// <param name="name">トラックバーの名前</param> /// <param name="window">トラックバーの親ウィンドウ名</param> /// <param name="callback">スライダの位置が変更されるたびに呼び出されるデリゲート</param> #else /// <summary> /// Constructor (value=0, max=100) /// </summary> /// <param name="name">Trackbar name</param> /// <param name="window">Window name</param> /// <param name="callback">Callback handler</param> #endif internal CvTrackbar(string name, string window, TrackbarCallback callback) : this(name, window, 0, 100, callback) { }
internal static extern int cvCreateTrackbar( string trackbar_name, string window_name, ref int value, int count, TrackbarCallback on_change);