saveAsync()

Description

Saves images in DcsBuffer to the App sandbox directory asynchronously.

Syntax

(void) saveAsync: (NSArray *) indices
file: (NSString *) filename
encodeParameter: (DcsEncodeParameter *) parameter
successCallback: (onSaveSuccess) onSuccess
failureCallback: (onSaveFailure) onFailure
progressCallback: (onSaveProgress) onProgress

Parameters

indices:NSArray The indices of images to be saved.
filename:NSString The file name of the images to be saved. It is a full path defined by users.
parameter:DcsEncodeParameter Its value will be chosen from DcsPNGEncodeParameter, DcsJPEGEncodeParameter or DcsPDFEncodeParameter which represents to save the images as PNG, JPG or PDF files.
onSuccess:onSaveSuccess The callback function when this method performs successfully.
onFailure:onSaveFailure The callback function when this method performs unsuccessfully.
onProgress:onSaveProgress The callback function when this method pushes the save progress information. This function will be triggered when each image is processed.

Return value

Void

Remarks

encodeParameter Maximum Value Result if the length of indices exceeds the maximum value
DcsPNGEncodeParameter 1 Save the first image as a PNG file.
DcsJPEGEncodeParameter 1 Save the first image as a JPG file.
DcsPDFEncodeParameter no limit Save the images as a multi-page PDF.

Exceptions

Circumstance Exception thrown via onFailure callback
License verification failed. DcsLicenseVerificationFailedException
There is not enough memory. DcsStorageSpaceLimitException
Indices/encodeParameter/file is nil. DcsValueNotValidException
Indices include a value not smaller than DcsBuffer.count. DcsValueOutOfRangeException
The file size exceeded the 50MB limit. DcsException
void (^onSaveSuccess) (id result)
Description This event is triggered when saveAsync function is successfully executed.
Parameter result: The source of the data. It represents the file name or the buffer stream saveAsync passed.
(^onSaveFailure) (id result, DcsException *exp) -> void
Description This event is triggered when saveAsync function is not successfully executed.
Parameter result: The source of the data. It represents the file name or the buffer stream saveAsync loaded.
exp: The exception saveAsync throws.
BOOL (^onSaveProgress) (NSInteger progress)
Description This event is triggered when saveAsync function is executing and showing the progress.
Parameter progress: The progress of saving files.
Return When YES is returned, saveAsync will keep executing. When NO is returned, saveAsync will stop.

Example

    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 saveAsync:tempArr file: path1 encodeParameter:pdf
     successCallback:^(id source) {
        NSLog(@"Success");
    } failureCallback:^(id source, DcsException *exp) {
        NSLog(@"%@%@",exp.name,exp.reason);
    } progressCallback:^BOOL(NSInteger progress) {
        return YES;
    }];

    [dcsView.io save:tempArr file: path2 encodeParameter:png]; // Only the first element in the array will be saved as a png file.
Is this page helpful?

Leave a Reply

Your email address will not be published.