Centering/Sizing Image for PHAsset

421 views Asked by At

Posting a whole lot here lately... Anyways... Im trying to get the gallery to show what the iPod Photos app will show as the thumbnail. Their thumbnail seems to be centered and all have equal size. For mine, They seem all good, except one image will be smaller.

Here is the code that gets called when I throw these into a table view cell:

func getAssetPhoto(asset: PHAsset, w: Double, h: Double) -> UIImage {
    let manager = PHImageManager.defaultManager()
    var option = PHImageRequestOptions()
    var photo = UIImage()
    var cropSideLength = min(asset.pixelWidth, asset.pixelHeight);
    var square = CGRect(x: 0.0, y: 0.0, width: Double(cropSideLength), height: Double(cropSideLength));

    var cropRect = CGRectApplyAffineTransform(square, CGAffineTransformMakeScale(CGFloat(1.0 / Double(asset.pixelWidth)), CGFloat(1.0 / Double(asset.pixelHeight))));
    option.synchronous = true
    option.normalizedCropRect = cropRect //CGRect(x: 0.5, y: 0.5, width: w, height: h)
    option.resizeMode = .Exact


    manager.requestImageForAsset(asset, targetSize: CGSize(width: w, height: h), contentMode: .AspectFill, options: option, resultHandler: {(result, info)->Void in
        photo = result
    })
    return photo
}

I also can't seem to get it to select the center of the image (tried changing rect to 0.5, 0.5).

Image of example at: http://tinypic.com/view.php?pic=1195tug&s=8#.VYL9PGB8Pdk The dragon should be centered. The pikachu is smaller than the rest...

0

There are 0 answers