Load images or files into DcsBuffer

With Dynamsoft Camera Mobile iOS Edition, you can load the memory data into DcsBuffer with the method loadData() or loadDataAsync(). Below is a simple code snippet for loadDataAsync():


UIImage *Rimg = [UIImage imageNamed:@"twain"];
NSData *newdata = UIImagePNGRepresentation(Rimg);
[self.dcsView.io loadDataAsync:newdata mode:DME_IMAGE successCallback:^(id source) {
     NSLog(@"Success");
} failureCallback:^(id source, DcsException *exp) {
     NSLog(@"%@%@",exp.name,exp.reason);
} progressCallback:^BOOL(NSInteger progress) {
     NSLog(@"%d",progress);
     return true;
}];

var image=UIImage(named:"capture.png")
        let data=UIImagePNGRepresentation(image!)
        dcsView.io.loadDataAsync(data, mode: DME_IMAGE, successCallback: { (test) in
            print("successful")
        }, failureCallback: { (test, exp) in
            print(exp?.description)
        }) { (progress) -> Bool in
            print(progress)
            return true
        }

You can also load a file in the App sandbox directory into DcsBuffer with the methods loadFile() or loadFileAsync().

    //@"tempname.png" is the name of the file saved by self.dcsView.io save() method.
    [self.dcsView.io loadFileAsync:@"tempname.png" mode:DME_IMAGE
    successCallback:^(id source) {
        NSLog(@"Success");
    } failureCallback:^(id source, DcsException *exp) {
        NSLog(@"%@%@",exp.name,exp.reason);
    } progressCallback:^BOOL(NSInteger progress) {
        return YES;
    }];
//@"capture.png" is the name of the file saved by dcsView.io.save() method.
        dcsView.io.loadFileAsync("capture.png", mode: DME_IMAGE, successCallback: { (test) in
            print("successful")
        }, failureCallback: { (test, exp) in
            print(exp?.description)
        }) { (progress) -> Bool in
            print(progress)
            return true
        }
Is this page helpful?

Leave a Reply

Your email address will not be published.