Skip to content

Commit

Permalink
fixed bug where some images got a white line on the right or bottom. …
Browse files Browse the repository at this point in the history
…(ex: 1500x1001 pixel image gets a white line on the bottom)
  • Loading branch information
shanebdavis committed Mar 10, 2015
1 parent 8187630 commit 623d445
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/ios/SOSPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ - (void) getPictures:(CDVInvokedUrlCommand *)command {

// Create the an album controller and image picker
ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] init];

if (maximumImagesCount == 1) {
albumController.immediateReturn = true;
albumController.singleSelection = true;
} else {
albumController.immediateReturn = false;
albumController.singleSelection = false;
}

ELCImagePickerController *imagePicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
imagePicker.maximumImagesCount = maximumImagesCount;
imagePicker.returnsOriginalImage = 1;
Expand Down Expand Up @@ -69,11 +69,11 @@ - (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPic
do {
filePath = [NSString stringWithFormat:@"%@/%@%03d.%@", docsPath, CDV_PHOTO_PREFIX, i++, @"jpg"];
} while ([fileMgr fileExistsAtPath:filePath]);

@autoreleasepool {
ALAssetRepresentation *assetRep = [asset defaultRepresentation];
CGImageRef imgRef = NULL;

//defaultRepresentation returns image as it appears in photo picker, rotated and sized,
//so use UIImageOrientationUp when creating our image below.
if (picker.returnsOriginalImage) {
Expand All @@ -82,15 +82,15 @@ - (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPic
} else {
imgRef = [assetRep fullScreenImage];
}

UIImage* image = [UIImage imageWithCGImage:imgRef scale:1.0f orientation:orientation];
if (self.width == 0 && self.height == 0) {
data = UIImageJPEGRepresentation(image, self.quality/100.0f);
} else {
UIImage* scaledImage = [self imageByScalingNotCroppingForSize:image toSize:targetSize];
data = UIImageJPEGRepresentation(scaledImage, self.quality/100.0f);
}

if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
break;
Expand All @@ -100,7 +100,7 @@ - (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPic
}

}

if (nil == result) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:resultStrings];
}
Expand Down Expand Up @@ -143,7 +143,7 @@ - (UIImage*)imageByScalingNotCroppingForSize:(UIImage*)anImage toSize:(CGSize)fr
} else {
scaleFactor = widthFactor; // scale to fit width
}
scaledSize = CGSizeMake(width * scaleFactor, height * scaleFactor);
scaledSize = CGSizeMake(floor(width * scaleFactor), floor(height * scaleFactor));
}

UIGraphicsBeginImageContext(scaledSize); // this will resize
Expand Down

1 comment on commit 623d445

@shanebdavis
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a "floor" to the scaledSize for iOS so, when scaling, the draw function doesn't perform an anti-alias operation at the right or bottom edge leaving a "white line" in the image.

Please sign in to comment.