Build the “Hello World” Document Capture View

If you haven't installed the Dynamsoft Camera SDK framework in your Xcode project, please refer here. Once installed, you can add code to implement image capture function in your project.

1. Open ViewController.m file
You can see the default ViewController.m as the following:default view controller

2. Import the framework's header

#import <DynamsoftCameraSDK/DcsView.h>
#import <DynamsoftCameraSDK/DcsUIImageGalleryView.h>
#import <DynamsoftCameraSDK/DcsUIVideoView.h>

3. Make changes to ViewController

@interface ViewController () {
    DcsView *dcsView;
    UIButton *openVideoViewButton;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    dcsView = [[DcsView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    //Show VideoView when DcsView is loaded
    dcsView.currentView = DVE_VIDEOVIEW;
    
    ///////////////////video view settting//////////////////
    //Set the videoview capture mode to document mode
    dcsView.videoView.mode = DME_DOCUMENT;
    
    //Set the next view after the cancel or capture button is clicked.
    dcsView.videoView.nextViewAfterCancel = DVE_IMAGEGALLERYVIEW;
    dcsView.videoView.nextViewAfterCapture= DVE_EDITORVIEW;
    
    [self.view addSubview:dcsView];
    
    openVideoViewButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.center.x-100, self.view.center.y-20, 200, 40)];
    [openVideoViewButton setTitle:@"Back to Camera" forState:normal];
    [openVideoViewButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [openVideoViewButton addTarget:self action:@selector(onClick) forControlEvents:UIControlEventTouchUpInside];
    
    [dcsView.imageGalleryView addSubview:openVideoViewButton];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) onClick{
    dcsView.currentView = DVE_VIDEOVIEW;
}


@end


4. See it in action

If you launch the Hello World project, it should look like this:

document capture 2.1

Once the capture button is clicked, the captured document will show up in the built-in editor view:

doc-editor view

After editing, you can click "OK" to see the cropped document in the gallery view:

Hello world document capture_after capture

As you can see, there are many other sample applications (source code provided) available for you to explore some of the many features of the Dynamsoft Camera SDK. Enjoy!

1. Open ViewController.swift file
2. Make changes to ViewController

class ViewController: UIViewController {
    var openVideoViewButton:UIButton!
    var dcsView:DcsView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        dcsView = DcsView.self.init(frame:CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height));
        
        //Show VideoView when DcsView is loaded
        dcsView.currentView=DVE_VIDEOVIEW
        
        ///////////////////video view settting//////////////////
        //Set the videoview capture mode to document mode
        dcsView.videoView.mode = DME_DOCUMENT
        
        //Set the next view after the cancel or capture button is clicked.
        dcsView.videoView.nextViewAfterCancel = DVE_IMAGEGALLERYVIEW
        dcsView.videoView.nextViewAfterCapture = DVE_EDITORVIEW
        
        view.addSubview(dcsView)
        
        openVideoViewButton = UIButton(frame:CGRect(x:self.view.center.x-100, y:self.view.center.y-20, width: 200, height: 40))
        openVideoViewButton.setTitle("Back to Camera", for: .normal)
        openVideoViewButton.setTitleColor(UIColor.blue, for: .normal)
        openVideoViewButton.addTarget(self, action:#selector(onClick), for:UIControlEvents.touchUpInside);
        dcsView.imageGalleryView.addSubview(openVideoViewButton)
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @objc func onClick(){
        dcsView.currentView=DVE_VIDEOVIEW
    }
}

3. See it in action

If you launch the Hello World project, it should look like this:

document capture 2.1

Once the capture button is clicked, the captured document will show up in the built-in editor view:

doc-editor view

After editing, you can click "OK" to see the cropped document in the gallery view:

Hello world document capture_after capture

As you can see, there are many other sample applications (source code provided) available for you to explore some of the many features of the Dynamsoft Camera SDK. Enjoy!

Is this page helpful?

Leave a Reply

Your email address will not be published.