rFlex / SCRecorder

iOS camera engine with Vine-like tap to record, animatable filters, slow motion, segments editing
Apache License 2.0
3.06k stars 583 forks source link

SCImageView does not take into account ContentMode while rendering #265

Open renjithn opened 8 years ago

renjithn commented 8 years ago

This used to be working properly in the past but I see this issue in later versions of this library. The rendering seems to follow UIViewContentModeScaleToFill regardless of what scaleAndResizeCIImageAutomatically value is and the output is stretched as a result.

Referring an old version I managed to fix this momentarily by replacing the following line in the method

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { }

[_context.CIContext drawImage:image inRect:rect fromRect:image.extent];

with

[_context.CIContext drawImage:image inRect:[self processRect:rect withImageSize:image.extent.size] fromRect:image.extent]; 

- (CGRect)processRect:(CGRect)rect withImageSize:(CGSize)imageSize {

    rect = CGRectMultiply(rect, 1);

    if (self.contentMode != UIViewContentModeScaleToFill) {
        CGFloat horizontalScale = rect.size.width / imageSize.width;
        CGFloat verticalScale = rect.size.height / imageSize.height;

        BOOL shouldResizeWidth = self.contentMode == UIViewContentModeScaleAspectFit ? horizontalScale > verticalScale : verticalScale > horizontalScale;
        BOOL shouldResizeHeight = self.contentMode == UIViewContentModeScaleAspectFit ? verticalScale > horizontalScale : horizontalScale > verticalScale;

        if (shouldResizeWidth) {
            CGFloat newWidth = imageSize.width * verticalScale;
            rect.origin.x = (rect.size.width / 2 - newWidth / 2);
            rect.size.width = newWidth;
        } else if (shouldResizeHeight) {
            CGFloat newHeight = imageSize.height * horizontalScale;
            rect.origin.y = (rect.size.height / 2 - newHeight / 2);
            rect.size.height = newHeight;
        }
    }

    return rect;
}
rico237 commented 8 years ago

This property helped me get things done in ## SCImageView.m at line 53 change the line to this _scaleAndResizeCIImageAutomatically = NO; The preview picture should not be resized now :)

bradleyayers commented 8 years ago

@renjithn can you raise a pull request for this so we can try and get it into a release?