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:@"xxx"];
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:"xxx")
let data=UIImagePNGRepresentation(image!)
dcsView.io.loadDataAsync(data, mode: DME_IMAGE, successCallback: { (source: Any) in
            print("successful")
        }, failureCallback: { (source: Any, exp: DcsException!) in
            print(exp.description)
        }) { (Int: 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().

    [self.dcsView.io loadFileAsync:@"<your saving path>" mode:DME_IMAGE
    successCallback:^(id source) {
        NSLog(@"Success");
    } failureCallback:^(id source, DcsException *exp) {
        NSLog(@"%@%@",exp.name,exp.reason);
    } progressCallback:^BOOL(NSInteger progress) {
        return YES;
    }];
        dcsView.io.loadFileAsync("<your saving path>", mode: DME_IMAGE, successCallback: { (source: Any) in
            print("successful")
        }, failureCallback: { (source: Any, exp: DcsException!) in
            print(exp.description)
        }) { (Int: progress) -> Bool in
            print(progress)
            return true
        }
Is this page helpful?