1

I used the codes below to save images to photo librabry

 for(int i=0;i<[imageNameArray count];i++)
{


    NSMutableString *sss=[[NSMutableString  alloc] initWithString: myAppPath];
    [sss appendString:@"/"] ;
    [sss appendString: [NSString stringWithFormat:@"%@",[imageNameArray objectAtIndex:i]  ] ] ;
    UIImage *image = [[[UIImage alloc] initWithContentsOfFile:sss]autorelease];
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    [sss release];

}

but sometimes, it can not save images correctly, I found that in photo library, there are one or more black blocks replace the saved images in thumbnail mode, but if I click the black blocks, the original images can display correctly.

Is there anyone met the same problem?

Welcome any comment

Thanks

interdev

arachide
  • 8,006
  • 18
  • 71
  • 134

1 Answers1

1

It could be a problem that you're saving the images in quick succession, and as a result, the save calls are overlapping. (It takes longer to write an image to the disk than it does to return from the function).

As far as I understand the save image function is asynchronous, and allows a delegate/call back to be registered (in the places where you're passing nil).

You should probably wait until one image has finished writing until you start another.

You can engineer this using the delegate and callbacks. To make it better for the user and to give them an idea of whats happening, you can display a progress bar and other information such as "1/3 images saved" etc.

Edit:

For a better context, I looked up the documentation:

The UIImageWriteToSavedPhotosAlbum function is declared as such:

void UIImageWriteToSavedPhotosAlbum (
   UIImage  *image,
   id       completionTarget,
   SEL      completionSelector,
   void     *contextInfo
);

you should set the completionTarget (likely to be self) and the completionSelector which should have the following signature:

- (void)               image: (UIImage *) image
    didFinishSavingWithError: (NSError *) error
                 contextInfo: (void *) contextInfo;

In the completion selector, you can perform the logic of whether or not you need to perform another save, and update your 'progress' UI.

Jasarien
  • 58,279
  • 31
  • 157
  • 188