Search code examples
c#.netzoomingcanon-sdk

zoomRect, zoomCoordinates brings PROPERTİES_UNAVAILABLE error in Canon EDSDK


I am able to use canon sdk using this library found in codeproject Canon EDSDK Library

Using SDK and the library mentioned above, I have to move the zoomed live view up/down/left/right. I can zoom but I cant move it to see the right place to adjust the manual zoom.

I have searched and I have come to zoomRect, zoomPosition, zoomCoordinates Then I have added these two methods to camera.cs and call them from DownloadEvf() method just after I got the evfImageRef . then I pass it to the methods. But a rect is created but changes everytime and values are crazy. the error code is Properties_unavailable

Another point is zoompositon in SDK also not working or I cannot make it work so it gives not supported error. I am also adding the code for it.

Rectangle object is EOSDigital.SDK.Rectangle object. CanonSDK is EOSDigital.SDK.CanonSDK object. MainCamera is Camera object.

    private Rectangle GetEvfZoomRect(IntPtr imgRef)
    {

        int size = Marshal.SizeOf(typeof(Rectangle));
        IntPtr ptr = Marshal.AllocHGlobal(size);
        ErrorCode err = CanonSDK.EdsGetPropertyData(imgRef, PropertyID.Evf_ZoomRect, 0, size, ptr);
        Rectangle rect = (Rectangle)Marshal.PtrToStructure(ptr, typeof(Rectangle));
        Marshal.FreeHGlobal(ptr);
        if (err == ErrorCode.OK)
            return rect;
        else
            return new Rectangle();
    }

    private Size GetEvfCoord(IntPtr imgRef)
    {
        int size = Marshal.SizeOf(typeof(Size));
        IntPtr ptr = Marshal.AllocHGlobal(size);

        ErrorCode err = CanonSDK.EdsGetPropertyData(imgRef, PropertyID.Evf_CoordinateSystem, 0, size, ptr);
        Size coord = (Size)Marshal.PtrToStructure(ptr, typeof(Size));
        Marshal.FreeHGlobal(ptr);
        if (err == ErrorCode.OK)
            return coord;
        else
            return new Size();
    }

this is how I try to send zoom position

        if (MainCamera.IsLiveViewOn)
        {
            EOSDigital.SDK.Point p = new EOSDigital.SDK.Point(100, 300);

            MainCamera.SetSetting(PropertyID.Evf_ZoomPosition, p);

        }

Solution

  • Here is the solution I have found. Use this method to set zoom position of camera . I have defined this method in camera.cs in library

        public void SetZoomPositionSetting(PropertyID propID, Point value, int inParam = 0)
        {
            CheckState();
    
            int size = Marshal.SizeOf(typeof(Point));
            ErrorCode err = CanonSDK.EdsSetPropertyData(CamRef, propID, inParam, size, value);
        }
    

    I have send this data to the method to change the zoomPosition

    MainCamera.SetZoomPositionSetting(PropertyID.Evf_ZoomPosition, p);
    

    p in here is EOSDigital.SDK.Point instance.

    Here are the methods to get zoomCoordinates, zoomRect. I have defined these methods in camera.cs in library

       private Rectangle GetEvfZoomRect(IntPtr imgRef)
        {
            Rectangle rect = new Rectangle();
    
            ErrorCode err = CanonSDK.GetPropertyData(imgRef, PropertyID.Evf_ZoomRect, 0, out rect);
            if (err == ErrorCode.OK)
                return rect;
            else
                return rect = new Rectangle();
    
        }
    
        private Size GetEvfCoord_Size(IntPtr imgRef)
        {
            Size size = new Size();
    
            ErrorCode err = CanonSDK.GetPropertyData(imgRef, PropertyID.Evf_CoordinateSystem, 0, out size);
            if (err == ErrorCode.OK)
                return size;
            else
                return new Size();
        }
    

    You need to call these methods within DownloadEvf() method in camera.cs. just after getting evfImageRef from
    CanonSDK.EdsDownloadEvfImage(CamRef, evfImageRef);

    NOT FROM CanonSDK.EdsCreateEvfImageRef(stream.Reference, out evfImageRef); this is why I have got that error

    after you get the evfImageRef with image data you can call the get methods using evfImageRef as imgRef.

    you can get the zoomposition using the same way. Note: by the way everytime you make a change, you need to rebuild the library.