-
Notifications
You must be signed in to change notification settings - Fork 138
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
base: master
Are you sure you want to change the base?
Changes from all commits
24bafd8
49ebf79
dc51af3
99078d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
const int FRAME_PIC_WIDTH = 20; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
||
|
@@ -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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||
|
@@ -330,14 +332,12 @@ -(void)getMovieFrame{ | |
|
||
AVAsset *myAsset = [[AVURLAsset alloc] initWithURL:_videoUrl options:nil]; | ||
self.imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:myAsset]; | ||
self.imageGenerator.appliesPreferredTrackTransform = YES; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Remove the code like this: |
||
|
||
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; | ||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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++; | ||
|
||
|
@@ -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; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
|
@@ -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; | ||
|
There was a problem hiding this comment.
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