示例#1
0
        /// <summary>
        /// Draw shapes onto the control
        /// </summary>
        /// <param name="imageInfo"></param>
        private void drawShapes(ActiveFlyCapLib.ImageInfo imageInfo)
        {
            int iThickness = (int)(0.005 * Math.Max(imageInfo.lRows, imageInfo.lCols));

            // Rectangle
            axActiveFlyCapControl.DrawRectangle(
                (short)(imageInfo.lCols / 3),
                (short)(imageInfo.lRows / 3),
                (short)((imageInfo.lCols * 2) / 3),
                (short)((imageInfo.lRows * 2) / 3),
                (short)iThickness,
                255,
                0,
                0);

            // Vertical line
            axActiveFlyCapControl.DrawLine(
                (short)(imageInfo.lCols / 2),
                0,
                (short)(imageInfo.lCols / 2),
                (short)imageInfo.lRows,
                (short)iThickness,
                0,
                255,
                0);

            // Circle
            int iRadius = (int)(0.03 * Math.Max(imageInfo.lRows, imageInfo.lCols));

            axActiveFlyCapControl.DrawEllipse(
                (short)((imageInfo.lCols / 2) - iRadius),
                (short)((imageInfo.lRows / 2) - iRadius),
                (short)((imageInfo.lCols / 2) + iRadius),
                (short)((imageInfo.lRows / 2) + iRadius),
                (short)iThickness,
                128,
                0,
                128);

            // Text
            // Graphics unit needs to be point
            Font newFont = new Font(
                FontFamily.GenericSansSerif,
                36,
                FontStyle.Regular,
                GraphicsUnit.Point);

            axActiveFlyCapControl.Font = newFont;
            axActiveFlyCapControl.DrawText(
                10,
                10,
                "Frames Captured: " + m_lFramesCaptured.ToString(),
                255,
                0,
                0);
        }
示例#2
0
        /// <summary>
        /// Calculate the image average
        /// </summary>
        /// <param name="imageInfo"></param>
        /// <returns></returns>
        private int calcImageAvg(ActiveFlyCapLib.ImageInfo imageInfo)
        {
            // Comment this out if you want to calculate the average
            return(0);

            // This should only be called if the control is not in free
            // running mode
            if (axActiveFlyCapControl.GetGrabMode() == ActiveFlyCapLib.GrabMode.FreeRunning)
            {
                return(0);
            }

            long lAvg       = 0;
            int  iImageSize = imageInfo.lRows * imageInfo.lRowInc;

            unsafe
            {
                // Get the pointer to the data
                object obj    = axActiveFlyCapControl.GetImagePtr(ActiveFlyCapLib.ImageType.RawImage);
                int    temp   = (int)obj;
                byte * pArray = (byte *)temp;

                // Iterate over the array and calculate the average
                for (int i = 0; i < iImageSize; i++)
                {
                    try
                    {
                        lAvg += pArray[i];
                    }
                    catch (System.AccessViolationException e_accessViolation)
                    {
                        Debug.WriteLine("Exception: " + e_accessViolation.ToString());
                    }
                }

                lAvg /= iImageSize;
            }

            return((int)lAvg);
        }