Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's dangerous to use the fullResolutionImage for this task for several reasons. Some remarks:</p> <ol> <li>For large images memory problems could occur. when using the fullResolutionImage method. Please note, that the Photo-Library (on the iPad at least) can also contain RAW-images.</li> <li>The performance is suboptimal as internally from the imagefile ImageIO creates first a CGImageRef that is then converted to a JPEG. This takes time.</li> <li>The AssetLibrary can also contain videos. In such a case fullResolutionImage only returns a previewImage of the video, but not the actual video.</li> <li>It's no problem to store the actual Asset-Objects as these are small in memory. </li> </ol> <p>A far better approach to write out the images to the documents directory, would be to use the getBytes method of ALAssetsRepresentation. This should be way faster and more efficient memory wise. It also gives you the original image file (incl. metadata) and also works for videos.</p> <p>Your example code rewritten then would look like that:</p> <pre><code>//reading out the orginal images for (int j=0; j&lt;[assetArray count]; j++) { ALAssetRepresentation *representation = [[assetArray objectAtIndex:j] defaultRepresentation]; NSString* filename = [documentPath stringByAppendingPathComponent:[representation filename]]; [[NSFileManager defaultManager] createFileAtPath:filename contents:nil attributes:nil]; NSOutputStream *outPutStream = [NSOutputStream outputStreamToFileAtPath:filename append:YES]; [outPutStream open]; long long offset = 0; long long bytesRead = 0; NSError *error; uint8_t * buffer = malloc(131072); while (offset&lt;[representation size] &amp;&amp; [outPutStream hasSpaceAvailable]) { bytesRead = [representation getBytes:buffer fromOffset:offset length:131072 error:&amp;error]; [outPutStream write:buffer maxLength:bytesRead]; offset = offset+bytesRead; } [outPutStream close]; free(buffer); } //reading out the fullScreenImages and thumbnails for (int j=0; j&lt;[assetArray count]; j++) { @autoreleasepool { ALAsset *asset = [assetArray objectAtIndex:j]; NSString *orgFilename = [representation filename]; NSString *filenameFullScreen = [NSString stringWithFormat:@"%@_fullscreen.png",[orgFilename stringByDeletingPathExtension]] NSString* pathFullScreen = [documentPath stringByAppendingPathComponent:filenameFullScreen]; CGImageRef imageRefFullScreen = [[asset defaultRepresentation] fullScreenImage]; UIImage *imageFullScreen = [UIImage imageWithCGImage:imageRefFullScreen]; NSData *imageDataFullScreen = UIImagePNGRepresentation(imageFullScreen); [imageDataFullScreen writeToFile:pathFullScreen atomically:YES]; NSString *filenameThumb = [NSString stringWithFormat:@"%@_thumb.png",[orgFilename stringByDeletingPathExtension]] NSString* pathThumb = [documentPath stringByAppendingPathComponent:filenameThumb]; CGImageRef imageRefThumb = [asset thumbnail]; UIImage *imageThumb = [UIImage imageWithCGImage:imageRefThumb]; NSData *imageDataThumb = UIImagePNGRepresentation(imageThumb); [imageDataThumb writeToFile:pathThumb atomically:YES]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload