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

Dealing frame image distortion #16

Open
wants to merge 4 commits 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
46 changes: 15 additions & 31 deletions SAVideoRangeSlider/SAVideoRangeSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ @implementation SAVideoRangeSlider

#define SLIDER_BORDERS_SIZE 6.0f
#define BG_VIEW_BORDERS_SIZE 3.0f
#define FRAME_IMAGEVIEW_CONTENT_MODE UIViewContentModeScaleAspectFill
Copy link
Author

Choose a reason for hiding this comment

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

adjust the contentMode of frame ImageView

const int FRAME_PIC_WIDTH = 20;
Copy link
Author

Choose a reason for hiding this comment

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

Extraction the constants of frame imageView width



- (id)initWithFrame:(CGRect)frame videoUrl:(NSURL *)videoUrl{

self = [super initWithFrame:frame];
if (self) {

Expand All @@ -56,6 +57,7 @@ - (id)initWithFrame:(CGRect)frame videoUrl:(NSURL *)videoUrl{
int thumbWidth = ceil(frame.size.width*0.05);

_bgView = [[UIControl alloc] initWithFrame:CGRectMake(thumbWidth-BG_VIEW_BORDERS_SIZE, 0, frame.size.width-(thumbWidth*2)+BG_VIEW_BORDERS_SIZE*2, frame.size.height)];
[_bgView.layer setMasksToBounds:YES];
Copy link
Author

Choose a reason for hiding this comment

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

clip the excess frame imageView(subview)

_bgView.layer.borderColor = [UIColor grayColor].CGColor;
_bgView.layer.borderWidth = BG_VIEW_BORDERS_SIZE;
[self addSubview:_bgView];
Expand Down Expand Up @@ -330,14 +332,12 @@ -(void)getMovieFrame{

AVAsset *myAsset = [[AVURLAsset alloc] initWithURL:_videoUrl options:nil];
self.imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:myAsset];
self.imageGenerator.appliesPreferredTrackTransform = YES;
Copy link
Author

Choose a reason for hiding this comment

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

apply the track matrix (or matrices) when extracting an image from the asset.
correct orientation while extracting the frame image.
Cooperate with the maximumSize of AVAssetImageGenerator, you did not adjust the width of frameImageView` frame.

Remove the code like this:
CGRect rect=tmp.frame;
rect.size.width=picWidth;
tmp.frame=rect;


if ([self isRetina]){
self.imageGenerator.maximumSize = CGSizeMake(_bgView.frame.size.width*2, _bgView.frame.size.height*2);
} else {
self.imageGenerator.maximumSize = CGSizeMake(_bgView.frame.size.width, _bgView.frame.size.height);
}
CGFloat scale = [[UIScreen mainScreen] scale];
self.imageGenerator.maximumSize = CGSizeMake(_bgView.frame.size.width*scale, _bgView.frame.size.height*scale);

int picWidth = 20;
int picWidth = FRAME_PIC_WIDTH;

// First image
NSError *error;
Expand All @@ -351,11 +351,10 @@ -(void)getMovieFrame{
videoScreen = [[UIImage alloc] initWithCGImage:halfWayImage];
}
UIImageView *tmp = [[UIImageView alloc] initWithImage:videoScreen];
CGRect rect=tmp.frame;
rect.size.width=picWidth;
tmp.frame=rect;
tmp.contentMode = FRAME_IMAGEVIEW_CONTENT_MODE;
[tmp.layer setMasksToBounds:YES];

[_bgView addSubview:tmp];
picWidth = tmp.frame.size.width;
CGImageRelease(halfWayImage);
}

Expand All @@ -381,35 +380,18 @@ -(void)getMovieFrame{

CGImageRef halfWayImage = [self.imageGenerator copyCGImageAtTime:timeFrame actualTime:&actualTime error:&error];

UIImage *videoScreen;
if ([self isRetina]){
videoScreen = [[UIImage alloc] initWithCGImage:halfWayImage scale:2.0 orientation:UIImageOrientationUp];
} else {
videoScreen = [[UIImage alloc] initWithCGImage:halfWayImage];
}

UIImage *videoScreen = [[UIImage alloc] initWithCGImage:halfWayImage scale:[[UIScreen mainScreen] scale] orientation:UIImageOrientationUp];


UIImageView *tmp = [[UIImageView alloc] initWithImage:videoScreen];

tmp.contentMode = FRAME_IMAGEVIEW_CONTENT_MODE;
[tmp.layer setMasksToBounds:YES];


CGRect currentFrame = tmp.frame;
currentFrame.origin.x = ii*picWidth;

currentFrame.size.width=picWidth;
prefreWidth+=currentFrame.size.width;

if( i == picsCnt-1){
currentFrame.size.width-=6;
}
tmp.frame = currentFrame;
int all = (ii+1)*tmp.frame.size.width;

if (all > _bgView.frame.size.width){
int delta = all - _bgView.frame.size.width;
currentFrame.size.width -= delta;
}

ii++;

Expand Down Expand Up @@ -456,6 +438,8 @@ -(void)getMovieFrame{


UIImageView *tmp = [[UIImageView alloc] initWithImage:videoScreen];
tmp.contentMode = FRAME_IMAGEVIEW_CONTENT_MODE;
[tmp.layer setMasksToBounds:YES];

int all = (i+1)*tmp.frame.size.width;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
842D00DA16F7A68100BC2959 /* SASliderLeft.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D00D416F7A68100BC2959 /* SASliderLeft.m */; };
842D00DB16F7A68100BC2959 /* SASliderRight.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D00D616F7A68100BC2959 /* SASliderRight.m */; };
842D00DC16F7A68100BC2959 /* SAVideoRangeSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 842D00D816F7A68100BC2959 /* SAVideoRangeSlider.m */; };
9EDFED28191D1FAA00528292 /* VideoRangeSlider.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 9EDFED27191D1FAA00528292 /* VideoRangeSlider.podspec */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -218,7 +217,6 @@
842D009E16F7064700BC2959 /* [email protected] in Resources */,
842D00A416F7064700BC2959 /* ViewController_iPhone.xib in Resources */,
842D00A716F7064700BC2959 /* ViewController_iPad.xib in Resources */,
9EDFED28191D1FAA00528292 /* VideoRangeSlider.podspec in Resources */,
842D00C116F70AF500BC2959 /* thaiPhuketKaronBeach.MOV in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down