Exemple #1
0
        /// <summary>
        ///     Gets the page bounds for all pages of the given PDF. If a relevant rotation is supplied, the bounds will
        ///     be rotated accordingly before returning.
        /// </summary>
        /// <param name="rotation">The rotation that should be applied</param>
        /// <param name="password">The password for the pdf file (if required)</param>
        /// <returns></returns>
        public static Size[] GetPageBounds(IPdfSource source, ImageRotation rotation = ImageRotation.None,
            string password = null)
        {
            Func<double, double, Size> sizeCallback = (width, height) => new Size(width, height);

            if (rotation == ImageRotation.Rotate90 || rotation == ImageRotation.Rotate270)
                sizeCallback = (width, height) => new Size(height, width); // switch width and height

            using (var stream = new PdfFileStream(source))
            {
                ValidatePassword(stream.Document, password);

                var pageCount = NativeMethods.CountPages(stream.Document); // gets the number of pages in the document
                var resultBounds = new Size[pageCount];

                for (var i = 0; i < pageCount; i++)
                {
                    var p = NativeMethods.LoadPage(stream.Document, i); // loads the page
                    var pageBound = NativeMethods.BoundPage(stream.Document, p);

                    resultBounds[i] = sizeCallback(pageBound.Width, pageBound.Height);

                    NativeMethods.FreePage(stream.Document, p); // releases the resources consumed by the page
                }

                return resultBounds;
            }
        }
		public PageDisplaySettings(int imagesPerRow, ViewType viewType, double horizontalOffsetBetweenPages, ImageRotation rotation = ImageRotation.None, float zoomFactor = 1.0f)
		{
			this.ImagesPerRow = imagesPerRow;
			this.ZoomFactor = zoomFactor;
			this.ViewType = viewType;
			this.HorizontalOffsetBetweenPages = viewType == ViewType.SinglePage ? 0 : horizontalOffsetBetweenPages;
			this.Rotation = rotation;
		}
 public static RightAngledRotation TranslateToRightAngledRotation(ImageRotation imageRotation)
 {
   switch (imageRotation)
   {
     case ImageRotation.Rot_0:
       return RightAngledRotation.Zero;
     case ImageRotation.Rot_90:
       return RightAngledRotation.HalfPi;
     case ImageRotation.Rot_180:
       return RightAngledRotation.Pi;
     case ImageRotation.Rot_270:
       return RightAngledRotation.ThreeHalfPi;
   }
   return RightAngledRotation.Zero;
 }
 public void Rotate(ImageRotation rotation)
 {
     var currentPage = innerPanel.GetCurrentPageIndex(ViewType) + 1;
     LoadPdf(CurrentSource, CurrentPassword);
     innerPanel.GotoPage(currentPage);
 }
Exemple #5
0
        public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs)
        {
            List <CameraSummary> summaries = new List <CameraSummary>();

            List <CameraSummary> found = new List <CameraSummary>();

            uEye.Types.CameraInformation[] devices;
            uEye.Info.Camera.GetCameraList(out devices);

            foreach (uEye.Types.CameraInformation device in devices)
            {
                string identifier = device.SerialNumber;
                bool   cached     = cache.ContainsKey(identifier);

                if (cached)
                {
                    deviceIds[identifier] = device.DeviceID;
                    summaries.Add(cache[identifier]);
                    found.Add(cache[identifier]);
                    continue;
                }

                string             alias            = device.Model;
                Bitmap             icon             = null;
                SpecificInfo       specific         = new SpecificInfo();
                Rectangle          displayRectangle = Rectangle.Empty;
                CaptureAspectRatio aspectRatio      = CaptureAspectRatio.Auto;
                ImageRotation      rotation         = ImageRotation.Rotate0;
                deviceIds[identifier] = device.DeviceID;

                if (blurbs != null)
                {
                    foreach (CameraBlurb blurb in blurbs)
                    {
                        if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier)
                        {
                            continue;
                        }

                        // We already know this camera, restore the user custom values.
                        alias            = blurb.Alias;
                        icon             = blurb.Icon ?? defaultIcon;
                        displayRectangle = blurb.DisplayRectangle;
                        if (!string.IsNullOrEmpty(blurb.AspectRatio))
                        {
                            aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio);
                        }
                        if (!string.IsNullOrEmpty(blurb.Rotation))
                        {
                            rotation = (ImageRotation)Enum.Parse(typeof(ImageRotation), blurb.Rotation);
                        }
                        specific = SpecificInfoDeserialize(blurb.Specific);
                        break;
                    }
                }

                icon = icon ?? defaultIcon;

                CameraSummary summary = new CameraSummary(alias, device.Model, identifier, icon, displayRectangle, aspectRatio, rotation, specific, this);

                summaries.Add(summary);
                found.Add(summary);
                cache.Add(identifier, summary);

                //log.DebugFormat("IDS uEye device enumeration: {0} (id:{1}).", summary.Alias, identifier);
            }

            List <CameraSummary> lost = new List <CameraSummary>();

            foreach (CameraSummary summary in cache.Values)
            {
                if (!found.Contains(summary))
                {
                    lost.Add(summary);
                }
            }

            foreach (CameraSummary summary in lost)
            {
                cache.Remove(summary.Identifier);
            }

            return(summaries);
        }
 public PageDisplaySettings(int imagesPerRow, ViewType viewType, double horizontalOffsetBetweenPages, ImageRotation rotation = ImageRotation.None, float zoomFactor = 1.0f)
 {
     this.ImagesPerRow = imagesPerRow;
     this.ZoomFactor   = zoomFactor;
     this.ViewType     = viewType;
     this.HorizontalOffsetBetweenPages = viewType == ViewType.SinglePage ? 0 : horizontalOffsetBetweenPages;
     this.Rotation = rotation;
 }
Exemple #7
0
        /// <summary>
        /// Sets the rotation for the given image.
        /// </summary>
        /// <param name="imageId">The id of the image.</param>
        /// <param name="degrees">The new rotation for the image. Can only be 0, 90, 180 or 270.</param>
        /// <returns></returns>
        public Task<PSIImageInfoSingleResponse> SetRotation(int imageId, ImageRotation degrees)
        {
            var request = CreateNonRestPSIRequest(ServiceName, "data", "setRotation");

            request.AddParameter(new
            {
                imageId = imageId,
                degrees = (int)degrees
            });

            return ExecuteAsync<PSIImageInfoSingleResponse>(request);
        }
Exemple #8
0
 public static bool GetOrientationMetadata(MediaItem mediaItem, out ImageRotation rotation, out bool flipX, out bool flipY)
 {
   rotation = ImageRotation.Rot_0;
   flipX = false;
   flipY = false;
   MediaItemAspect imageAspect;
   if (mediaItem != null && mediaItem.Aspects.TryGetValue(ASPECT_ID, out imageAspect))
   {
     int orientationInfo = (int) imageAspect[ATTR_ORIENTATION];
     return (OrientationToRotation(orientationInfo, out rotation) &&
       OrientationToFlip(orientationInfo, out flipX, out flipY));
   }
   return false;
 }
Exemple #9
0
 /// <summary>
 /// Translates the EXIF orientation info to a rotation. The value should be used to apply a rotation
 /// to show a image correctly oriented.
 /// </summary>
 /// <param name="orientationInfo">Orientation info, stored in attribute <see cref="ATTR_ORIENTATION"/>.</param>
 /// <param name="rotation">Returns the rotation in clockwise direction.</param>
 /// <returns><c>true</c>, if the rotation could successfully be decoded from the given <paramref name="orientationInfo"/>,
 /// else <c>false</c>.</returns>
 public static bool OrientationToRotation(int orientationInfo, out ImageRotation rotation)
 {
   switch (orientationInfo)
   {
     case 1:
     case 2:
       rotation = ImageRotation.Rot_0;
       break;
     case 3:
     case 4:
       rotation = ImageRotation.Rot_180;
       break;
     case 6:
     case 7:
       rotation = ImageRotation.Rot_90;
       break;
     case 5:
     case 8:
       rotation = ImageRotation.Rot_270;
       break;
     default:
       rotation = ImageRotation.Rot_0;
       return false;
   }
   return true;
 }
        public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs)
        {
            // DirectShow has active discovery. We just ask for the list of cameras connected to the PC.
            List <CameraSummary> summaries = new List <CameraSummary>();
            List <CameraSummary> found     = new List <CameraSummary>();

            FilterInfoCollection cameras = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            foreach (FilterInfo camera in cameras)
            {
                if (IsBlackListed(camera.Name))
                {
                    continue;
                }

                // For now consider that the moniker string is like a serial number.
                // Cameras that don't have a serial number will appear to be new when changing USB port.
                string identifier = camera.MonikerString;
                bool   cached     = cache.ContainsKey(identifier);

                string             alias            = camera.Name;
                Bitmap             icon             = null;
                SpecificInfo       specific         = null;
                Rectangle          displayRectangle = Rectangle.Empty;
                CaptureAspectRatio aspectRatio      = CaptureAspectRatio.Auto;
                ImageRotation      rotation         = ImageRotation.Rotate0;
                bool mirror = false;

                if (blurbs != null)
                {
                    foreach (CameraBlurb blurb in blurbs)
                    {
                        if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier)
                        {
                            continue;
                        }

                        alias            = blurb.Alias;
                        icon             = blurb.Icon ?? SelectDefaultIcon(identifier);
                        displayRectangle = blurb.DisplayRectangle;
                        if (!string.IsNullOrEmpty(blurb.AspectRatio))
                        {
                            aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio);
                        }
                        if (!string.IsNullOrEmpty(blurb.Rotation))
                        {
                            rotation = (ImageRotation)Enum.Parse(typeof(ImageRotation), blurb.Rotation);
                        }
                        mirror   = blurb.Mirror;
                        specific = SpecificInfoDeserialize(blurb.Specific);
                        VendorHelper.IdentifyModel(identifier);
                        break;
                    }
                }

                if (icon == null)
                {
                    icon = SelectDefaultIcon(identifier);
                }

                CameraSummary summary = new CameraSummary(alias, camera.Name, identifier, icon, displayRectangle, aspectRatio, rotation, mirror, specific, this);
                summaries.Add(summary);

                if (cached)
                {
                    found.Add(cache[identifier]);
                }

                if (!cached)
                {
                    cache.Add(identifier, summary);
                    found.Add(summary);
                    log.DebugFormat("DirectShow device enumeration: {0} (moniker:{1}).", summary.Alias, identifier);
                }
            }

            // TODO: do we need to do all this. Just replace the cache with the current list.

            List <CameraSummary> lost = new List <CameraSummary>();

            foreach (CameraSummary summary in cache.Values)
            {
                if (!found.Contains(summary))
                {
                    lost.Add(summary);
                }
            }

            foreach (CameraSummary summary in lost)
            {
                cache.Remove(summary.Identifier);
            }

            return(summaries);
        }
 /* Sets the appropriate material properties based on how the image should be rotated. */
 private void SetImageRotation(ImageRotation rotation)
 {
     EffectMaterial.SetFloat("_FlipU", rotation.FlipHorizontally ? 1 : 0);
     EffectMaterial.SetFloat("_FlipV", rotation.FlipVertically ? 1 : 0);
     EffectMaterial.SetFloat("_Rotate", rotation.Rotate ? 1 : 0);
 }
    /* Defines how the frame should be rotated and scaled in order for it to be properly rendered. */
    private void UpdateOrientation(ScreenOrientation screenOrientation)
    {
        /* Compute the required rotation of the frame. */
        var rotation = new ImageRotation(false, false, false);

#if !UNITY_EDITOR
        switch (screenOrientation)
        {
        case ScreenOrientation.LandscapeLeft:
            rotation = new ImageRotation(false, false, false);
            break;

        case ScreenOrientation.LandscapeRight:
            rotation = new ImageRotation(true, true, false);
            break;

        case ScreenOrientation.Portrait:
            rotation = new ImageRotation(false, true, true);
            break;

        case ScreenOrientation.PortraitUpsideDown:
            rotation = new ImageRotation(true, false, true);
            break;
        }

        if (FlipImage)
        {
            rotation.FlipVertically   = !rotation.FlipVertically;
            rotation.FlipHorizontally = !rotation.FlipHorizontally;
        }
#endif

        SetImageRotation(rotation);

        /* Compute the required scaling and panning factors of the frame. */
        float frameAspectRatio  = (float)_currentFrame.width / (float)_currentFrame.height;
        float screenAspectRatio = (float)Screen.width / (float)Screen.height;

        float ratio = 1.0f;

#if !UNITY_EDITOR
        switch (screenOrientation)
        {
        case ScreenOrientation.LandscapeLeft:
        case ScreenOrientation.LandscapeRight:
            ratio = frameAspectRatio / screenAspectRatio;
            break;

        case ScreenOrientation.Portrait:
        case ScreenOrientation.PortraitUpsideDown:
            ratio = frameAspectRatio * screenAspectRatio;
            break;
        }
#else
        ratio = frameAspectRatio / screenAspectRatio;
#endif


        /* Sets the appropriate material properties based on how the image should be scaled and panned. */
        EffectMaterial.SetFloat("_Scale", ratio);
        EffectMaterial.SetFloat("_Pan", (1.0f - ratio) / 2.0f);
    }
        public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs)
        {
            List <CameraSummary> summaries = new List <CameraSummary>();
            List <CameraSummary> found     = new List <CameraSummary>();

            List <IGXDeviceInfo> devices = new List <IGXDeviceInfo>();

            igxFactory.UpdateDeviceList(200, devices);

            foreach (IGXDeviceInfo device in devices)
            {
                string identifier = device.GetSN();
                bool   cached     = cache.ContainsKey(identifier);

                if (cached)
                {
                    // We've already seen this camera in the current Kinovea session.
                    //deviceIds[identifier] = device.GetDeviceID();
                    summaries.Add(cache[identifier]);
                    found.Add(cache[identifier]);
                    continue;
                }

                string             alias            = device.GetDisplayName();
                Bitmap             icon             = null;
                SpecificInfo       specific         = new SpecificInfo();
                Rectangle          displayRectangle = Rectangle.Empty;
                CaptureAspectRatio aspectRatio      = CaptureAspectRatio.Auto;
                ImageRotation      rotation         = ImageRotation.Rotate0;
                //deviceIndices[identifier] = device.GetDeviceID();

                if (blurbs != null)
                {
                    foreach (CameraBlurb blurb in blurbs)
                    {
                        if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier)
                        {
                            continue;
                        }

                        // We know this camera from a previous Kinovea session, restore the user custom values.
                        alias            = blurb.Alias;
                        icon             = blurb.Icon ?? defaultIcon;
                        displayRectangle = blurb.DisplayRectangle;
                        if (!string.IsNullOrEmpty(blurb.AspectRatio))
                        {
                            aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio);
                        }
                        if (!string.IsNullOrEmpty(blurb.Rotation))
                        {
                            rotation = (ImageRotation)Enum.Parse(typeof(ImageRotation), blurb.Rotation);
                        }
                        specific = SpecificInfoDeserialize(blurb.Specific);
                        break;
                    }
                }

                icon = icon ?? defaultIcon;

                CameraSummary summary = new CameraSummary(alias, device.GetDisplayName(), identifier, icon, displayRectangle, aspectRatio, rotation, specific, this);

                summaries.Add(summary);
                found.Add(summary);
                cache.Add(identifier, summary);
            }

            List <CameraSummary> lost = new List <CameraSummary>();

            foreach (CameraSummary summary in cache.Values)
            {
                if (!found.Contains(summary))
                {
                    lost.Add(summary);
                }
            }

            foreach (CameraSummary summary in lost)
            {
                cache.Remove(summary.Identifier);
            }

            return(summaries);
        }
Exemple #14
0
 /// <summary>
 /// Force a specific image rotation.
 /// </summary>
 /// <returns>returns true if the cache has been invalidated by the operation</returns>
 public virtual bool ChangeImageRotation(ImageRotation rotation)
 {
     // Does nothing by default. Override to implement.
     return(false);
 }
        public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs)
        {
            List <CameraSummary> summaries = new List <CameraSummary>();

            // We don't do the discover step every time to avoid UI freeze since Enumerate takes some time.
            if (discoveryStep > 0)
            {
                discoveryStep = (discoveryStep + 1) % discoverySkip;
                foreach (CameraSummary summary in cache.Values)
                {
                    summaries.Add(summary);
                }

                return(summaries);
            }

            discoveryStep = 1;
            List <CameraSummary> found = new List <CameraSummary>();

            List <DeviceEnumerator.Device> devices = DeviceEnumerator.EnumerateDevices();

            foreach (DeviceEnumerator.Device device in devices)
            {
                string identifier = device.FullName;

                bool cached = cache.ContainsKey(identifier);
                if (cached)
                {
                    deviceIndices[identifier] = device.Index;
                    summaries.Add(cache[identifier]);
                    found.Add(cache[identifier]);
                    continue;
                }

                string             alias            = device.Name;
                Bitmap             icon             = null;
                SpecificInfo       specific         = new SpecificInfo();
                Rectangle          displayRectangle = Rectangle.Empty;
                CaptureAspectRatio aspectRatio      = CaptureAspectRatio.Auto;
                ImageRotation      rotation         = ImageRotation.Rotate0;
                bool mirror = false;
                deviceIndices[identifier] = device.Index;

                if (blurbs != null)
                {
                    foreach (CameraBlurb blurb in blurbs)
                    {
                        if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier)
                        {
                            continue;
                        }

                        // We already know this camera, restore the user custom values.
                        alias            = blurb.Alias;
                        icon             = blurb.Icon ?? defaultIcon;
                        displayRectangle = blurb.DisplayRectangle;
                        if (!string.IsNullOrEmpty(blurb.AspectRatio))
                        {
                            aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio);
                        }

                        if (!string.IsNullOrEmpty(blurb.Rotation))
                        {
                            rotation = (ImageRotation)Enum.Parse(typeof(ImageRotation), blurb.Rotation);
                        }

                        mirror   = blurb.Mirror;
                        specific = SpecificInfoDeserialize(blurb.Specific);
                        break;
                    }
                }

                icon = icon ?? defaultIcon;

                CameraSummary summary = new CameraSummary(alias, device.Name, identifier, icon, displayRectangle, aspectRatio, rotation, mirror, specific, this);

                summaries.Add(summary);
                found.Add(summary);
                cache.Add(identifier, summary);
            }

            List <CameraSummary> lost = new List <CameraSummary>();

            foreach (CameraSummary summary in cache.Values)
            {
                if (!found.Contains(summary))
                {
                    lost.Add(summary);
                }
            }

            foreach (CameraSummary summary in lost)
            {
                cache.Remove(summary.Identifier);
            }

            return(summaries);
        }
 public DisplaySettings(int imagesPerRow, ViewType viewType, double horizontalOffsetBetweenPages, ImageRotation rotation = ImageRotation.NONE, float zoomFactor = 1.0f)
 {
     this.ImagesPerRow = imagesPerRow;
     this.ZoomFactor   = zoomFactor;
     this.ViewType     = viewType;
     this.HOffsetPage  = viewType == ViewType.SINGLE_PAGE ? 0 : horizontalOffsetBetweenPages;
     this.Rotation     = rotation;
 }
 public void Rotate(ImageRotation rotation)
 {
     var currentPage = this.innerPanel.GetCurrentPageIndex(this.ViewType) + 1;
     this.LoadPdf(this.CurrentSource, this.CurrentPassword);
     this.innerPanel.GotoPage(currentPage);
 }
 /// <summary>
 /// Определить тип поворота
 /// </summary>
 private static RotateFlipType ImageRotationToRotateFlipType(ImageRotation imageRotation) =>
 imageRotation switch
 {
Exemple #19
0
 /// <summary>
 /// Translates the given <paramref name="rotation"/> to an angle in degrees.
 /// </summary>
 /// <param name="rotation">Rotation to be translated.</param>
 /// <returns>Number degrees in clockwise direction, corresponding to the given <paramref name="rotation"/>.</returns>
 public static int RotationToDegrees(ImageRotation rotation)
 {
   switch (rotation)
   {
     case ImageRotation.Rot_0:
       return 0;
     case ImageRotation.Rot_90:
       return 90;
     case ImageRotation.Rot_180:
       return 180;
     case ImageRotation.Rot_270:
       return 270;
     default:
       return 0;
   }
 }
Exemple #20
0
 private async Task <MediaPacket> ApplyAsync(TransformHandle handle, MediaPacket source,
                                             ImageRotation rotation)
 {
     NativeTransform.SetRotation(handle, rotation);
     return(await RunAsync(handle, source));
 }
        public static void RotatePng(ParsedPath pngPath, ImageRotation rotation)
        {
            if (rotation == ImageRotation.None)
                return;

            using (ImageSurface originalImage = new ImageSurface(pngPath))
            {
                int w;
                int h;

                if (rotation == ImageRotation.Left || rotation == ImageRotation.Right)
                {
                    w = originalImage.Height;
                    h = originalImage.Width;
                }
                else
                {
                    w = originalImage.Width;
                    h = originalImage.Height;
                }

                double[] rotationRadians = {0, -Math.PI / 2, Math.PI / 2, Math.PI };

                using (ImageSurface rotatedImage = new ImageSurface(Format.Argb32, w, h))
                {
                    using (Cairo.Context g = new Cairo.Context(rotatedImage))
                    {
                        g.Translate(rotatedImage.Width / 2.0, rotatedImage.Height / 2.0);
                        g.Rotate(rotationRadians[(int)rotation]);
                        g.Translate(-originalImage.Width / 2.0, -originalImage.Height / 2.0);

                        g.SetSourceSurface(originalImage, 0, 0);
                        g.Paint();
                    }

                    rotatedImage.WriteToPng(pngPath);
                }
            }
        }
Exemple #22
0
        /// <summary>
        /// Rotates an image.
        /// </summary>
        /// <param name="rotateValue">The ImageRotation enumeration value.</param>
        /// <param name="originalPathFile">Source file, could be the same as the change file.</param>
        /// <param name="changeImagePathFile">The file to receive the change.</param>
        /// <returns>True for success.</returns>
        public bool Rotate(ImageRotation rotateValue, string originalPathFile, string changeImagePathFile)
        {
            bool bRet = false;

            if (null == originalPathFile) return false;
            if (null == changeImagePathFile) return false;

            if (originalPathFile.Length > 0)  // may have been set at creation, so not given
                m_originalFile = originalPathFile;

            // Fix slashes - never trust that they have done this.
            m_originalFile = m_originalFile.Replace('/', '\\').Replace("\\\\", "\\");
            changeImagePathFile = changeImagePathFile.Replace('/', '\\').Replace("\\\\", "\\");

            // use cximage library instead of .Net code
            if (m_originalFile != changeImagePathFile)
            {
                // copy file to new if needed
                StorageClient.Context.File.Copy(m_originalFile, changeImagePathFile, true);
                MakeWriteable(changeImagePathFile); // in case the original was readonly
            }
            ImageGalleryInterop.CImageResizerClass ig = new ImageGalleryInterop.CImageResizerClass();
            int angle = 0;
            switch (rotateValue)
            {
                case ImageRotation.Half180:
                    angle = 180;
                    break;
                case ImageRotation.Left90:
                    angle = -90;
                    break;
                case ImageRotation.Right90:
                    angle = 90;
                    break;
            }
            ig.RotateImageFile(changeImagePathFile, angle);

            /*
            RotateFlipType rfAction = RotateFlipType.Rotate90FlipNone;

            System.Drawing.Image img = System.Drawing.Image.FromFile(m_originalFile);

            switch (rotateValue)
            {
                case ImageRotation.None:
                    break;

                case ImageRotation.Half180:
                    rfAction = RotateFlipType.Rotate180FlipNone;
                    break;

                case ImageRotation.Left90:
                    rfAction = RotateFlipType.Rotate270FlipNone;
                    break;

                case ImageRotation.Right90:
                    rfAction = RotateFlipType.Rotate90FlipNone;
                    break;
            }

            img.RotateFlip(rfAction);

            img.Save(changeImagePathFile);

            // Save for convenient use.
            m_width = img.Width;
            m_height = img.Height;
            img.Dispose();
            */

            m_localResultFile = changeImagePathFile;

            bRet = true;

            return bRet;
        }
        public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs)
        {
            List <CameraSummary> summaries = new List <CameraSummary>();
            List <CameraSummary> found     = new List <CameraSummary>();

            //---------------------------------------------
            // Lifecycles of objects in the Baumer API:
            // - systemList: entire application. Will initialize all systems, not clear how to uninitialize non Baumer systems.
            // - system: entire application. Should be kept open.
            // - interface: entire application. Allow listing of devices even if they are opened by another application.
            // - device: camera session.
            //---------------------------------------------

            try
            {
                foreach (KeyValuePair <string, BGAPI2.System> systemPair in systems)
                {
                    BGAPI2.System system = systemPair.Value;
                    if (!system.Vendor.Contains("Baumer"))
                    {
                        continue;
                    }

                    if (!system.IsOpen)
                    {
                        system.Open();
                    }

                    if (string.IsNullOrEmpty(system.Id))
                    {
                        continue;
                    }

                    system.Interfaces.Refresh(200);
                    foreach (KeyValuePair <string, BGAPI2.Interface> interfacePair in system.Interfaces)
                    {
                        BGAPI2.Interface iface = interfacePair.Value;
                        //log.DebugFormat("Opening interface {0}", iface.DisplayName);
                        if (!iface.IsOpen)
                        {
                            iface.Open();
                        }

                        if (string.IsNullOrEmpty(iface.Id))
                        {
                            continue;
                        }

                        iface.Devices.Refresh(200);
                        //log.DebugFormat("Devices found in interface {0}: {1}.", iface.DisplayName, iface.Devices.Count);
                        foreach (KeyValuePair <string, BGAPI2.Device> devicePair in iface.Devices)
                        {
                            BGAPI2.Device device = devicePair.Value;
                            //log.DebugFormat("Found device: {0} ({1})", device.DisplayName, device.SerialNumber);

                            string identifier = device.SerialNumber;
                            bool   cached     = cache.ContainsKey(identifier);
                            if (cached)
                            {
                                // We've already seen this camera in the current Kinovea session.
                                //deviceIds[identifier] = device.GetDeviceID();
                                //log.DebugFormat("Known device from current session.");
                                summaries.Add(cache[identifier]);
                                found.Add(cache[identifier]);
                                continue;
                            }

                            string             alias            = device.DisplayName;
                            Bitmap             icon             = null;
                            SpecificInfo       specific         = new SpecificInfo();
                            Rectangle          displayRectangle = Rectangle.Empty;
                            CaptureAspectRatio aspectRatio      = CaptureAspectRatio.Auto;
                            ImageRotation      rotation         = ImageRotation.Rotate0;
                            bool mirror = false;

                            // Check if we already know this camera from a previous Kinovea session.
                            if (blurbs != null)
                            {
                                foreach (CameraBlurb blurb in blurbs)
                                {
                                    if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier)
                                    {
                                        continue;
                                    }

                                    // We know this camera from a previous Kinovea session, restore the user custom values.
                                    log.DebugFormat("Known device from previous session.");
                                    alias            = blurb.Alias;
                                    icon             = blurb.Icon ?? defaultIcon;
                                    displayRectangle = blurb.DisplayRectangle;
                                    if (!string.IsNullOrEmpty(blurb.AspectRatio))
                                    {
                                        aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio);
                                    }
                                    if (!string.IsNullOrEmpty(blurb.Rotation))
                                    {
                                        rotation = (ImageRotation)Enum.Parse(typeof(ImageRotation), blurb.Rotation);
                                    }
                                    mirror   = blurb.Mirror;
                                    specific = SpecificInfoDeserialize(blurb.Specific);
                                    break;
                                }
                            }

                            // Keep temporary info in order to find it back later.
                            specific.SystemKey    = systemPair.Key;
                            specific.InterfaceKey = interfacePair.Key;
                            specific.DeviceKey    = devicePair.Key;
                            specific.Device       = null;

                            icon = icon ?? defaultIcon;
                            CameraSummary summary = new CameraSummary(alias, device.DisplayName, identifier, icon, displayRectangle, aspectRatio, rotation, mirror, specific, this);

                            summaries.Add(summary);
                            found.Add(summary);
                            cache.Add(identifier, summary);
                        }

                        //iface.Close();
                    }

                    //system.Close();
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("Error while scanning for devices. {0}", e.Message);
            }

            List <CameraSummary> lost = new List <CameraSummary>();

            foreach (CameraSummary summary in cache.Values)
            {
                if (!found.Contains(summary))
                {
                    lost.Add(summary);
                }
            }

            foreach (CameraSummary summary in lost)
            {
                log.DebugFormat("Lost device: {0}", summary.Name);
                cache.Remove(summary.Identifier);
            }

            return(summaries);
        }
Exemple #24
0
        public void AddFile(string filename, Bitmap image, bool video, ImageRotation rotation)
        {
            CapturedFile capturedFile = new CapturedFile(filename, image, video, rotation);

            view.AddFile(capturedFile);
        }