Package edsdk.api

Examples of edsdk.api.CanonCamera


*
*/
public class CameraImageQuality {

    public static void main( final String[] args ) throws InterruptedException, IOException {
        final CanonCamera camera = new CanonCamera();
        camera.openSession();

        final long imageQuality = camera.getProperty( EdsPropertyID.kEdsPropID_ImageQuality );

        /*
         * kEdsPropID_ImageQuality
         * Bit num. Description Value
         * ----------------------------------------------------------------------
         * ----------------------------------
         * 24-31 Image Size of the main image Values defined in enum
         * EdsImageSize
         * 20-23 Image Format of the main image Values defined in enum
         * EdsImageType
         * 16-19 Image Compress Quality of the main image Values defined in enum
         * EdsImageCompressQuality
         * 12-15 reserved
         * 8-11 Image Size of the secondary image Values defined in enum
         * EdsImageSize
         * 4-7 Image Format of the secondary image Values defined in enum
         * EdsImageType
         * 0-3 Image Compress Quality of the secondary image Values defined in
         * enum EdsImageCompressQuality
         */
        final EdsImageSize mainImageSize = EdsImageSize.enumOfValue( (int) ( imageQuality >>> 24 & 0xf ) );
        final EdsImageType mainImageType = EdsImageType.enumOfValue( (int) ( imageQuality >>> 20 & 0xf ) );
        final EdsCompressQuality mainImageCompressQuality = EdsCompressQuality.enumOfValue( (int) ( imageQuality >>> 16 & 0xf ) );
        final EdsImageSize secondaryImageSize = EdsImageSize.enumOfValue( (int) ( imageQuality >>> 8 & 0xf ) );
        final EdsImageType secondaryImageType = EdsImageType.enumOfValue( (int) ( imageQuality >>> 4 & 0xf ) );
        final EdsCompressQuality secondaryImageCompressQuality = EdsCompressQuality.enumOfValue( (int) ( imageQuality & 0xf ) );

        camera.closeSession();
        CanonCamera.close();

        System.out.println();
        System.out.println( "Main image properties " );
        System.out.println( "                type: " +
View Full Code Here


    public static void main( final String[] args ) {

        SwingUtilities.invokeLater( new Runnable() {

            final CanonCamera camera = new CanonCamera();
            JFrame frame;
            JLabel label;
            JButton button;

            @Override
View Full Code Here

*
*/
public class Test {

    public static void main( final String[] args ) throws InterruptedException, IOException {
        final CanonCamera camera = new CanonCamera();

        if ( camera.openSession() ) {

            Long lvalue = Test.printProperty( camera, EdsPropertyID.kEdsPropID_BatteryLevel );
            System.out.println( lvalue == 0xffffffff
                                                    ? "On AC power"
                                                    : "On battery, value is percentage remaining." );

            lvalue = Test.printProperty( camera, EdsPropertyID.kEdsPropID_BatteryQuality );

            lvalue = Test.printProperty( camera, EdsPropertyID.kEdsPropID_DriveMode );

            for ( final EdsPropertyID id : EdsPropertyID.values() ) {
                Test.getPropertyDesc( camera.getEdsCamera(), id, true );
            }

            final EdsISOSpeed currentISOSpeed = EdsISOSpeed.enumOfValue( camera.getProperty( EdsPropertyID.kEdsPropID_ISOSpeed ).intValue() );
            final EdsISOSpeed[] availableISOSpeeds = camera.getAvailableISOSpeeds();
            if ( availableISOSpeeds != null ) {
                for ( final EdsISOSpeed e : availableISOSpeeds ) {
                    System.out.println( "ISO Speed " +
                                        e.description() +
                                        ( e.equals( currentISOSpeed )
                                                                     ? " *CURRENT* "
                                                                     : "" ) );
                }
            } else {
                System.out.println( "ISO Speed settings not configurable with current mode/lens" );
            }

            final EdsTv currentShutterSpeed = EdsTv.enumOfValue( camera.getProperty( EdsPropertyID.kEdsPropID_Tv ).intValue() );
            final EdsTv[] availableShutterSpeeds = camera.getAvailableShutterSpeeds();
            if ( availableShutterSpeeds != null ) {
                for ( final EdsTv e : availableShutterSpeeds ) {
                    System.out.println( "Shutter Speed " +
                                        e.description() +
                                        ( e.equals( currentShutterSpeed )
                                                                         ? " *CURRENT* "
                                                                         : "" ) );
                }
            } else {
                System.out.println( "Shutter speed is not configurable with current mode/lens" );
            }

            final EdsAv currentApertureValue = EdsAv.enumOfValue( camera.getProperty( EdsPropertyID.kEdsPropID_Av ).intValue() );
            final EdsAv[] availableApertureValues = camera.getAvailableApertureValues();
            if ( availableApertureValues != null ) {
                for ( final EdsAv e : availableApertureValues ) {
                    System.out.println( "Aperture " +
                                        e.description() +
                                        ( e.equals( currentApertureValue )
                                                                          ? " *CURRENT* "
                                                                          : "" ) );
                }
            } else {
                System.out.println( "Aperture value not configurable with current mode/lens" );
            }

            System.out.println( "Generic Array Test" );
            final EdsISOSpeed[] aa = Test.genericArrayTest( EdsISOSpeed[].class, new int[] {
                                                                                            0x30,
                                                                                            0x53,
                                                                                            0x68 } );
            for ( final EdsISOSpeed a : aa ) {
                System.out.println( " " + a.description() );
            }

            System.out.println( "\nMirror Lockup Setting: " +
                                camera.getCustomFunction( EdsCustomFunction.kEdsCustomFunction_MirrorLockup ) );

            camera.beginLiveView();

            // sleep a few seconds so live view can start
            Thread.sleep( 2000 );

            final ArrayList<EdsBaseRef> baserefs = new ArrayList<EdsBaseRef>();
            baserefs.add( camera.getEdsCamera() );

            final ByReference[] liverefs = CanonUtils.getLiveViewImageReference( camera.getEdsCamera() );
            if ( liverefs != null && liverefs.length > 0 && liverefs[0] != null ) {
                System.out.println( "\nlive view active so adding evf image reference" );
                baserefs.add( liverefs[0].getValue() );
            }

            System.out.println( "\nMirror Lockup Setting: " +
                                camera.getCustomFunction( EdsCustomFunction.kEdsCustomFunction_MirrorLockup ) );

            System.out.println( "\nLive View Histogram Status: " +
                                camera.getLiveViewHistogramStatus() );

            final boolean hideNegativeSizeProperties = true;
            final boolean hideNegativeSizeCustomFunctions = true;

            //TEST READING PROPERTIES FOR CAMERA AND LIVE VIEW
            System.out.println( "\nProperty Sizes" );
            System.out.println( "---------------------------------------" );
            for ( final EdsBaseRef baseref : baserefs ) {
                System.out.println( "\nGetting properties for: " +
                                    baseref.getClass().getSimpleName() );
                System.out.println( "---------------------------------------" );
                for ( final EdsPropertyID id : EdsPropertyID.values() ) {
                    final long size = CanonUtils.getPropertySize( baseref, id );

                    final EdsDataType type = CanonUtils.getPropertyType( baseref, id );

                    if ( size > -1 || !hideNegativeSizeProperties ) {
                        System.out.println( id.name() );
                        System.out.println( "  Size: " + size );
                        System.out.println( "  Type: " + type.description() );
                        if ( size == -1 &&
                             type.equals( EdsDataType.kEdsDataType_Unknown ) ) {
                            System.out.println( id.name() +
                                                " - VALUE NOT AVAILABLE ON THIS CAMERA AND/OR WITH CURRENT SETTINGS" );
                        } else {
                            final Object value;
                            switch ( type ) {
                                case kEdsDataType_String: {
                                    final String data = CanonUtils.getPropertyDataAdvanced( baseref, id );
                                    value = data;
                                    break;
                                }
                                case kEdsDataType_Rational: {
                                    final EdsRational struct = CanonUtils.getPropertyDataAdvanced( baseref, id );
                                    value = struct;
                                    break;
                                }
                                case kEdsDataType_Point: {
                                    final EdsPoint struct = CanonUtils.getPropertyDataAdvanced( baseref, id );
                                    value = struct;
                                    break;
                                }
                                case kEdsDataType_Rect: {
                                    final EdsRect struct = CanonUtils.getPropertyDataAdvanced( baseref, id );
                                    value = struct;
                                    break;
                                }
                                case kEdsDataType_Time: {
                                    final EdsTime struct = CanonUtils.getPropertyDataAdvanced( baseref, id );
                                    value = struct;
                                    break;
                                }
                                case kEdsDataType_FocusInfo: {
                                    final EdsFocusInfo struct = CanonUtils.getPropertyDataAdvanced( baseref, id );
                                    value = struct;
                                    break;
                                }
                                case kEdsDataType_PictureStyleDesc: {
                                    final EdsPictureStyleDesc struct = CanonUtils.getPropertyDataAdvanced( baseref, id );
                                    value = struct;
                                    break;
                                }
                                case kEdsDataType_ByteBlock:
                                case kEdsDataType_Int8_Array:
                                case kEdsDataType_UInt8_Array:
                                case kEdsDataType_Int16_Array:
                                case kEdsDataType_UInt16_Array:
                                case kEdsDataType_Int32_Array:
                                case kEdsDataType_UInt32_Array: {
                                    final int[] array = CanonUtils.getPropertyDataAdvanced( baseref, id );
                                    value = array;
                                    break;
                                }
                                default:
                                    value = Long.valueOf( CanonUtils.getPropertyData( baseref, id ) );
                            }
                            System.out.println( " Value: " +
                                                Test.toString( value ) );
                        }
                    }
                }
                System.out.println( "\n" );
            }

            //TEST READING CUSTOM FUNCTIONS
            System.out.println( "Custom Functions" );
            System.out.println( "---------------------------------------" );
            for ( int i = -10000; i < 10000; i++ ) {
                final long size = CanonUtils.getPropertySize( camera.getEdsCamera(), EdsPropertyID.kEdsPropID_CFn, i );

                final EdsDataType type = CanonUtils.getPropertyType( camera.getEdsCamera(), EdsPropertyID.kEdsPropID_CFn, i );

                if ( size > -1 || !hideNegativeSizeCustomFunctions ) {
                    System.out.println( "Number: " + i + " (0x" +
                                        Integer.toHexString( i ) + ")" );
                    System.out.println( "  Type: " + type.description() );
                    System.out.println( "  Size: " + size );
                    if ( size == -1 &&
                         type.equals( EdsDataType.kEdsDataType_Unknown ) ) {
                        System.out.println( " VALUE NOT AVAILABLE ON THIS CAMERA AND/OR WITH CURRENT SETTINGS" );
                    } else {
                        final Long value = CanonUtils.getPropertyData( camera.getEdsCamera(), EdsPropertyID.kEdsPropID_CFn, i );
                        System.out.println( " Value: " + value );
                        final EdsCustomFunction e = EdsCustomFunction.enumOfValue( i );
                        if ( e != null ) {
                            System.out.println( " Known: Yes, " + e.name() +
                                                " (" + e.description() + ")" );
                        } else {
                            System.out.println( " Known: NO" );
                        }
                    }
                }
            }
            System.out.println( "\n" );

            if ( liverefs != null ) {
                CanonUtils.release( liverefs );
            }

            //TEST GETTERS FROM CanonCamera
            System.out.println( "Property Getters in CanonCamera" );
            System.out.println( "---------------------------------------" );
            final Method[] methods = camera.getClass().getMethods();
            for ( final Method method : methods ) {
                if ( method.getName().startsWith( "get" ) &&
                     method.getParameterTypes().length == 0 ) {
                    System.out.println( "Trying " + method.getName() );
                    try {
                        final Object o = method.invoke( camera, (Object[]) null );
                        System.out.println( " Result: " + Test.toString( o ) );
                    }
                    catch ( final IllegalAccessException e ) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    catch ( final IllegalArgumentException e ) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    catch ( final InvocationTargetException e ) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
            System.out.println( "\n\n" );

            //TEST CUSTOM FUNCTION FROM CanonCamera
            System.out.println( "EdsCustomFunction with CanonCamera.getCustomFunction" );
            System.out.println( "----------------------------------------------------" );
            for ( final EdsCustomFunction e : EdsCustomFunction.values() ) {
                System.out.println( "\nTrying " + e.description() + " (" +
                                    e.name() + ")" );
                final Long result = camera.getCustomFunction( e );
                System.out.println( "    Value: " + Test.toString( result ) );
            }
            System.out.println( "\n" );

            //TEST FOR MISSING EdsPropID CONSTANTS
            System.out.println( "Testing if its possible to get values from the camera for undefined property IDs from 0x0 to 0xFFFF" );
            System.out.println( "----------------------------------------------------" );
            for ( int i = 0; i < 0xFFFF; i++ ) {
                if ( null == EdsPropertyID.enumOfValue( i ) ) {
                    final int bufferSize = 1;
                    final IntBuffer type = IntBuffer.allocate( bufferSize );
                    final NativeLongByReference number = new NativeLongByReference( new NativeLong( bufferSize ) );
                    EdsError err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPropertySize( camera.getEdsCamera(), new NativeLong( i ), new NativeLong( 0 ), type, number ) );
                    if ( !err.equals( EdsError.EDS_ERR_PROPERTIES_UNAVAILABLE ) ) {
                        System.out.println( i + " (0x" +
                                            Integer.toHexString( i ) + "): " +
                                            err.description() );
                    }
                    if ( err == EdsError.EDS_ERR_OK ) {
                        final int size = (int) number.getValue().longValue();
                        final EdsDataType edsType = EdsDataType.enumOfValue( type.get( 0 ) );
                        if ( size > -1 ) {
                            if ( edsType == null ||
                                 edsType.equals( EdsDataType.kEdsDataType_Unknown ) ) {
                                System.out.println( "WARNING: size is greater than -1 (" +
                                                    size +
                                                    "), but edsType is unknown!" );
                            } else {
                                final Memory memory = new Memory( size > 0
                                                                          ? size
                                                                          : 1 );
                                err = CanonUtils.toEdsError( CanonCamera.EDSDK.EdsGetPropertyData( camera.getEdsCamera(), new NativeLong( i ), new NativeLong( 0 ), new NativeLong( size ), memory ) );
                                if ( err == EdsError.EDS_ERR_OK ) {
                                    if ( edsType.equals( EdsDataType.kEdsDataType_Int32 ) ||
                                         edsType.equals( EdsDataType.kEdsDataType_UInt32 ) ) {
                                        System.out.println( "    property: " +
                                                            i +
                                                            " (0x" +
                                                            Integer.toHexString( i ) +
                                                            "), value: " +
                                                            memory.getNativeLong( 0 ) +
                                                            ", data type: " +
                                                            edsType.description() +
                                                            ", size: " + size );
                                    } else if ( edsType.equals( EdsDataType.kEdsDataType_String ) ) {
                                        System.out.println( "    property: " +
                                                            i +
                                                            " (0x" +
                                                            Integer.toHexString( i ) +
                                                            "), value: " +
                                                            memory.getString( 0 ) +
                                                            ", data type: " +
                                                            edsType.description() +
                                                            ", size: " + size );
                                    } else {
                                        System.out.println( "    property: " +
                                                            i +
                                                            " (0x" +
                                                            Integer.toHexString( i ) +
                                                            "), value: NOT SUPPORTED, data type: " +
                                                            edsType.description() +
                                                            ", size: " + size );
                                    }
                                }
                            }
                        }
                    }
                }
            }

            camera.endLiveView();

            //CanonUtils.isMirrorLockupEnabled( camera.getEdsCamera() );

            camera.closeSession();
        }

        CanonCamera.close();
    }
View Full Code Here

*
*/
public class E04_LiveView {

    public static void main( final String[] args ) throws InterruptedException {
        final CanonCamera camera = new CanonCamera();
        if ( camera.openSession() ) {
            if ( camera.beginLiveView() ) {
                final JFrame frame = new JFrame( "Live view" );
                final JLabel label = new JLabel();
                frame.getContentPane().add( label, BorderLayout.CENTER );
                frame.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
                frame.addWindowListener( new WindowAdapter() {

                    @Override
                    public void windowClosing( final WindowEvent e ) {
                        camera.endLiveView();
                        camera.closeSession();
                        CanonCamera.close();
                        System.exit( 0 );
                    }
                } );
                frame.setVisible( true );

                while ( true ) {
                    Thread.sleep( 50 );
                    final BufferedImage image = camera.downloadLiveView();
                    if ( image != null ) {
                        label.setIcon( new ImageIcon( image ) );
                        frame.pack();
                        image.flush();
                    }

                }
            }
            camera.closeSession();
        }
        CanonCamera.close();
        System.exit( 0 );
    }
View Full Code Here

import edsdk.utils.CanonConstants.EdsImageQuality;

public class E06_ListImageQuality {

  public static void main(String[] args) {
    CanonCamera cam = new CanonCamera();
    cam.openSession();
   
    // if you check out the CanonCamera class you'll find that there
    // are getAvailableXXX methods for all kinds of things!
    EdsImageQuality[] sizes = cam.getAvailableImageQualities()
    for( EdsImageQuality size : sizes ){
      System.out.println( size.name() + "/" + size.value() );
    }
    cam.closeSession();
    CanonCamera.close();
  }
View Full Code Here

*
*/
public class E02_Simpler {

    public static void main( final String[] args ) throws InterruptedException, IOException {
        final CanonCamera camera = new CanonCamera();

        if ( camera.openSession() ) {
            final File[] photos = camera.shoot( EdsSaveTo.kEdsSaveTo_Host );

            if ( photos != null ) {
                for ( final File photo : photos ) {
                    if ( photo != null ) {
                        System.out.println( "Saved photo as: " +
                                            photo.getCanonicalPath() );
                    }
                }
            }

            camera.closeSession();
        }

        CanonCamera.close();
    }
View Full Code Here

*/
public class E05_Timelapse {

    public static void main( final String[] args ) throws InterruptedException {
        //Native.setProtected( true );
        final CanonCamera camera = new CanonCamera();
        if ( camera.openSession() ) {

            E05_Timelapse.createUI( camera );

            while ( true ) {
                System.out.println( "=========================================" );
                final long level = camera.getBatteryLevel();
                if ( level != 0xffffffff ) {
                    System.out.println( "Battery Level = " + level );
                }

                camera.execute( new ShootCommand( EdsSaveTo.kEdsSaveTo_Host, 20, E05_Timelapse.filename() ) );

                try {
                    Thread.sleep( 15000 );
                }
                catch ( final InterruptedException e ) {
View Full Code Here

*
*/
public class E03_Mixed {

    public static void main( final String[] args ) throws InterruptedException {
        final CanonCamera camera = new CanonCamera();
        if ( camera.openSession() ) {

            final boolean result = camera.executeNow( new CanonCommand<Boolean>() {

                @Override
                public void run() {
                    // Do your thing here, like bulb shooting, setting properties,
                    // whatever you like!
                    //
                    // you have access to all edsdk methods using
                    // EDSDK.*
                    // Access to the above camera object using camera
                    // or if you need the edsObject that the camera is linked to
                    // use camera.getEdsCamera()
                    //
                    // when you're done set the result that should be returned.
                    setResult( true );
                }
            } );

            // Now do something with the result
            if ( !result ) {
                System.out.println( "oh, it didn't work... " );
            }

            camera.closeSession();
        }

        CanonCamera.close();
    }
View Full Code Here

TOP

Related Classes of edsdk.api.CanonCamera

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.