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:

    DcsPDFEncodeParameter *pdf;
    DcsPNGEncodeParameter *png;
    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.
    [dcsView.io save:tempArr file: path1 encodeParameter:pdf];
    [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.