Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing pixelated thumbs in iOS9 #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
version="1.0.7">

<name>ImagePicker</name>

<description>
This plugin allows selection of multiple images from the camera roll / gallery in a phonegap app
</description>

<license>MIT</license>

<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
</engines>

<js-module src="www/imagepicker.js" name="ImagePicker">
<clobbers target="plugins.imagePicker" />
Expand Down
36 changes: 17 additions & 19 deletions src/ios/ELCImagePicker/ELCAsset.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,31 @@ - (id)initWithAsset:(ALAsset*)asset
self = [super init];
if (self) {
self.asset = asset;
_selected = NO;
}
return self;
_selected = NO;
}
return self;
}

- (void)toggleSelection
{
self.selected = !self.selected;
self.selected = !self.selected;
}

- (void)setSelected:(BOOL)selected
{
if (selected) {
if ([_parent respondsToSelector:@selector(shouldSelectAsset:)]) {
if (![_parent shouldSelectAsset:self]) {
return;
}
}
}
_selected = selected;
if (selected) {
if (_parent != nil && [_parent respondsToSelector:@selector(assetSelected:)]) {
[_parent assetSelected:self];
}
}
if (selected) {
if ([_parent respondsToSelector:@selector(shouldSelectAsset:)]) {
if (![_parent shouldSelectAsset:self]) {
return;
}
}
}
_selected = selected;
if (selected) {
if (_parent != nil && [_parent respondsToSelector:@selector(assetSelected:)]) {
[_parent assetSelected:self];
}
}
}


@end

18 changes: 16 additions & 2 deletions src/ios/ELCImagePicker/ELCAssetCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,32 @@ - (void)setAssets:(NSArray *)assets
}
for (UIImageView *view in _overlayViewArray) {
[view removeFromSuperview];

}
//set up a pointer here so we don't keep calling [UIImage imageNamed:] if creating overlays
UIImage *overlayImage = nil;
for (int i = 0; i < [_rowAssets count]; ++i) {

ELCAsset *asset = [_rowAssets objectAtIndex:i];

// ALAsset's .thumbnail method's documention specifies that it returns an
// image of a size "appropirate for the platform", which makes it potentially
// highly unreliable. Indeed, before iOS9 it would return a 125px image, which
// was already too small for the 75 square (at double density), but the scaling
// artifacts were not that noticeable. As of iOS9, the AL* library is deprecated
// in favour of the new Photos library, and the .thumbnails method suddenly started
// returning images 75 pixels in width, which is half of what's needed for the
// double density 75 square, resulting in seriously pixelated thumbnails.
//
// Some dude on the internet pointed out that the aspectRatioThumbnail method
// still returns reasonably sized thumbs, and indeed they are on the order of 256 pixels.
if (i < [_imageViewArray count]) {
UIImageView *imageView = [_imageViewArray objectAtIndex:i];
imageView.image = [UIImage imageWithCGImage:asset.asset.thumbnail];
imageView.image = [UIImage imageWithCGImage:asset.asset.aspectRatioThumbnail];
} else {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:asset.asset.thumbnail]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:asset.asset.aspectRatioThumbnail]];
[imageView setClipsToBounds:true];
[imageView setContentMode:UIViewContentModeScaleAspectFill];
[_imageViewArray addObject:imageView];
}

Expand Down