Note that there are some explanatory texts on larger screens.

plurals
  1. POResize an ALAsset Photo takes a long time. Any way around this?
    primarykey
    data
    text
    <p>I have a blog application that I'm making. To compose a new entry, there is a "Compose Entry" view where the user can select a photo and input text. For the photo, there is a UIImageView placeholder and upon clicking this, a custom ImagePicker comes up where the user can select up to 3 photos.</p> <p>This is where the problem comes in. I don't need the full resolution photo from the ALAsset, but at the same time, the thumbnail is too low resolution for me to use.</p> <p>So what I'm doing at this point is resizing the fullResolution photos to a smaller size. However, this takes some time, especially when resizing up to 3 photos to a smaller size.</p> <p>Here is a code snipped to show what I'm doing:</p> <pre><code> ALAssetRepresentation *rep = [[dict objectForKey:@"assetObject"] defaultRepresentation]; CGImageRef iref = [rep fullResolutionImage]; if (iref) { CGRect screenBounds = [[UIScreen mainScreen] bounds]; UIImage *previewImage; UIImage *largeImage; if([rep orientation] == ALAssetOrientationUp) //landscape image { largeImage = [[UIImage imageWithCGImage:iref] scaledToWidth:screenBounds.size.width]; previewImage = [[UIImage imageWithCGImage:iref] scaledToWidth:300]; } else // portrait image { previewImage = [[[UIImage imageWithCGImage:iref] scaledToHeight:300] imageRotatedByDegrees:90]; largeImage = [[[UIImage imageWithCGImage:iref] scaledToHeight:screenBounds.size.height] imageRotatedByDegrees:90]; } } </code></pre> <p>Here, from the fullresolution image, I am creating two images: a preview image (max 300px on the long end) and a large image (max 960px or 640px on the long end). The preview image is what is shown on the app itself in the "new entry" preview. The large image is what will be used when uploading to the server.</p> <p>The actual code I'm using to resize, I grabbed somewhere from here:</p> <pre><code>-(UIImage*)scaledToWidth:(float)i_width { float oldWidth = self.size.width; float scaleFactor = i_width / oldWidth; float newHeight = self.size.height * scaleFactor; float newWidth = oldWidth * scaleFactor; UIGraphicsBeginImageContext(CGSizeMake(newWidth, newHeight)); [self drawInRect:CGRectMake(0, 0, newWidth, newHeight)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } </code></pre> <p>Am I doing things wrong here? As it stands, the ALAsset thumbnail is too low clarity, and at the same time, I dont need the entire full resolution. It's all working now, but the resizing takes some time. Is this just a necessary consequence?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    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. 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