Save images to App sandbox directory

With Dynamsoft Camera SDK iOS Edition, you can save the data in DcsBuffer as a file to the App sandbox directory using the methods save() or saveAsync(). You can also reload the saved file into the DcsBuffer via the method loadFile.

Below is a simple code snippet:

    @property (nonatomic,strong) DcsPDFEncodeParameter *pdf;
    @property (nonatomic,strong) DcsPNGEncodeParameter *png;
    @property (nonatomic,strong) DcsJPEGEncodeParameter *jpeg;

    _pdf = [[DcsPDFEncodeParameter alloc] init];
    _png = [[DcsPNGEncodeParameter alloc] init];
    _jpeg = [[DcsJPEGEncodeParameter alloc] init];
    
    _jpeg.quality = 0.8;
    NSString *path1 = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingString: @"/dynamsoftDcs.pdf"
    NSString *path2 = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingString: @"/dynamsoftDcs.png"
    NSArray *tempArr = [[NSArray alloc]initWithObjects:@"1",@"2",nil]; // @"1" and @"2" are the indices of the second and third data in DcsBuffer.
    [self.dcsView.io save:tempArr file: path1 encodeParameter:_pdf];
    [self.dcsView.io save:tempArr file: path2 encodeParameter:_png]; // Only the first element in the array will be saved as a png file.
        let png=DcsPNGEncodeParameter()
        let pdf=DcsPDFEncodeParameter()
        let jpg=DcsJPEGEncodeParameter()
        jpg.quality=0.8
        var path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + "dynamsoftDcs.png"
        dcsView.io.save([0], file: path, encodeParameter: png) //0 is the index of the first data in DcsBuffer
Is this page helpful?

Leave a Reply

Your email address will not be published.