diff --git a/Classes/ELCImagePicker/ELCAssetCell.m b/Classes/ELCImagePicker/ELCAssetCell.m index d456b11..f1de56a 100755 --- a/Classes/ELCImagePicker/ELCAssetCell.m +++ b/Classes/ELCImagePicker/ELCAssetCell.m @@ -40,6 +40,63 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus return self; } +- (UIImage *)imageForAsset:(ALAsset *)asset +{ + UIImage *image; + + image = [UIImage imageWithCGImage:asset.thumbnail]; + if([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) { + UIImage *typeImage; + UIView *view; + UIView *typeView; + NSNumber *duration; + UILabel *durationLabel; + NSInteger nbSeconds; + NSInteger nbMinutes; + NSInteger nbHours; + CAGradientLayer *gradientLayer; + UIImageView *imageView; + + imageView = [[UIImageView alloc] initWithImage:image]; + typeImage = [UIImage imageNamed:@"videoType.png"]; + + duration = [asset valueForProperty:ALAssetPropertyDuration]; + durationLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, image.size.height - 29, image.size.width - 10, 20)]; + durationLabel.textColor = [UIColor whiteColor]; + durationLabel.textAlignment = NSTextAlignmentRight; + durationLabel.font = [durationLabel.font fontWithSize:24]; + nbHours = duration.doubleValue/60/60; + nbMinutes = duration.doubleValue/60 - nbHours*60; + nbSeconds = duration.doubleValue - nbMinutes*60 - nbHours*60*60; + if(nbHours == 0) { + durationLabel.text = [NSString stringWithFormat:@"%02d:%02d", (int)nbMinutes, (int)nbSeconds]; + } + else { + durationLabel.text = [NSString stringWithFormat:@"%d:%02d:%02d", (int)nbHours, (int)nbMinutes, (int)nbSeconds]; + } + + gradientLayer = [CAGradientLayer layer]; + gradientLayer.colors = @[(id)[UIColor colorWithWhite:0 alpha:0].CGColor, (id)[UIColor colorWithWhite:0 alpha:0.7].CGColor]; + gradientLayer.frame = CGRectMake(0, image.size.height - 34, image.size.width , 34); + [imageView.layer addSublayer:gradientLayer]; + + view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)]; + typeView = [[UIImageView alloc] initWithImage:typeImage]; + [view addSubview:imageView]; + [view addSubview:typeView]; + [view addSubview:durationLabel]; + typeView.contentMode = UIViewContentModeCenter; + typeView.frame = CGRectMake(10, view.bounds.size.height - 31, 28, 28); + + UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0); + [view.layer renderInContext:UIGraphicsGetCurrentContext()]; + image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + } + + return image; +} + - (void)setAssets:(NSArray *)assets { self.rowAssets = assets; @@ -57,9 +114,9 @@ - (void)setAssets:(NSArray *)assets if (i < [_imageViewArray count]) { UIImageView *imageView = [_imageViewArray objectAtIndex:i]; - imageView.image = [UIImage imageWithCGImage:asset.asset.thumbnail]; + imageView.image = [self imageForAsset:asset.asset]; } else { - UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:asset.asset.thumbnail]]; + UIImageView *imageView = [[UIImageView alloc] initWithImage:[self imageForAsset:asset.asset]]; [_imageViewArray addObject:imageView]; } diff --git a/Classes/ELCImagePicker/Resources/videoType.png b/Classes/ELCImagePicker/Resources/videoType.png new file mode 100644 index 0000000..13ae8f3 Binary files /dev/null and b/Classes/ELCImagePicker/Resources/videoType.png differ diff --git a/Classes/ELCImagePicker/Resources/videoType@2x.png b/Classes/ELCImagePicker/Resources/videoType@2x.png new file mode 100644 index 0000000..dfe97ad Binary files /dev/null and b/Classes/ELCImagePicker/Resources/videoType@2x.png differ diff --git a/ELCImagePickerDemo.xcodeproj/project.pbxproj b/ELCImagePickerDemo.xcodeproj/project.pbxproj index eeecc92..55979d5 100755 --- a/ELCImagePickerDemo.xcodeproj/project.pbxproj +++ b/ELCImagePickerDemo.xcodeproj/project.pbxproj @@ -24,6 +24,9 @@ 2899E5220DE3E06400AC0155 /* ELCImagePickerDemoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2899E5210DE3E06400AC0155 /* ELCImagePickerDemoViewController.xib */; }; 28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD733E0D9D9553002E5188 /* MainWindow.xib */; }; 28D7ACF80DDB3853001CB0EB /* ELCImagePickerDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D7ACF70DDB3853001CB0EB /* ELCImagePickerDemoViewController.m */; }; + 4A3E18481A41FF7000AE971F /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A3E18471A41FF7000AE971F /* QuartzCore.framework */; }; + 4A3E184B1A4201E900AE971F /* videoType.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A3E18491A4201E900AE971F /* videoType.png */; }; + 4A3E184C1A4201E900AE971F /* videoType@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A3E184A1A4201E900AE971F /* videoType@2x.png */; }; 4AAFDA62194840F20020FCC4 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4AAFDA61194840F20020FCC4 /* MobileCoreServices.framework */; }; 83C6BC9714476B280064D71D /* elc-ios-icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 83C6BC9514476B280064D71D /* elc-ios-icon@2x.png */; }; 83C6BC9814476B280064D71D /* elc-ios-icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 83C6BC9614476B280064D71D /* elc-ios-icon.png */; }; @@ -60,6 +63,10 @@ 28D7ACF70DDB3853001CB0EB /* ELCImagePickerDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ELCImagePickerDemoViewController.m; sourceTree = ""; }; 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 32CA4F630368D1EE00C91783 /* ELCImagePickerDemo_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ELCImagePickerDemo_Prefix.pch; sourceTree = ""; }; + 4A3E18461A41FF1500AE971F /* ELCImagePickerHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ELCImagePickerHeader.h; sourceTree = ""; }; + 4A3E18471A41FF7000AE971F /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + 4A3E18491A4201E900AE971F /* videoType.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = videoType.png; path = Classes/ELCImagePicker/Resources/videoType.png; sourceTree = ""; }; + 4A3E184A1A4201E900AE971F /* videoType@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "videoType@2x.png"; path = "Classes/ELCImagePicker/Resources/videoType@2x.png"; sourceTree = ""; }; 4AAFDA61194840F20020FCC4 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; }; 5FAEB088190A3FA9002D73C4 /* ELCImagePickerHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ELCImagePickerHeader.h; sourceTree = ""; }; 83C6BC9514476B280064D71D /* elc-ios-icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "elc-ios-icon@2x.png"; sourceTree = ""; }; @@ -78,6 +85,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 4A3E18481A41FF7000AE971F /* QuartzCore.framework in Frameworks */, 4AAFDA62194840F20020FCC4 /* MobileCoreServices.framework in Frameworks */, 1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */, 1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */, @@ -148,6 +156,8 @@ 1A4C631317380272001E0978 /* Overlay@2x.png */, 83C6BC9514476B280064D71D /* elc-ios-icon@2x.png */, 83C6BC9614476B280064D71D /* elc-ios-icon.png */, + 4A3E18491A4201E900AE971F /* videoType.png */, + 4A3E184A1A4201E900AE971F /* videoType@2x.png */, 28AD733E0D9D9553002E5188 /* MainWindow.xib */, 8D1107310486CEB800E47090 /* ELCImagePickerDemo-Info.plist */, ); @@ -157,6 +167,7 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( + 4A3E18471A41FF7000AE971F /* QuartzCore.framework */, 4AAFDA61194840F20020FCC4 /* MobileCoreServices.framework */, E29A5E3B1239C42A008BB149 /* AssetsLibrary.framework */, 288765A40DF7441C002DB57D /* CoreGraphics.framework */, @@ -181,7 +192,7 @@ 1A2C0FFB17026CF0004FAFA0 /* ELCAssetTablePicker.m */, 1A2C100217026CF0004FAFA0 /* ELCImagePickerController.h */, 1A2C0FFC17026CF0004FAFA0 /* ELCImagePickerController.m */, - 5FAEB088190A3FA9002D73C4 /* ELCImagePickerHeader.h */, + 4A3E18461A41FF1500AE971F /* ELCImagePickerHeader.h */, F1DF783E196FA475003524A2 /* ELCConsole.h */, F1DF783F196FA475003524A2 /* ELCConsole.m */, F1DF7840196FA475003524A2 /* ELCOverlayImageView.h */, @@ -243,11 +254,13 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4A3E184C1A4201E900AE971F /* videoType@2x.png in Resources */, 28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */, 2899E5220DE3E06400AC0155 /* ELCImagePickerDemoViewController.xib in Resources */, 83C6BC9714476B280064D71D /* elc-ios-icon@2x.png in Resources */, 83C6BC9814476B280064D71D /* elc-ios-icon.png in Resources */, 230644BC15F8C0BB007679C7 /* MainWindow-iPad.xib in Resources */, + 4A3E184B1A4201E900AE971F /* videoType.png in Resources */, 0B67B05B17E0ED1F002CC2C5 /* Default-568h@2x.png in Resources */, 1A4C631417380272001E0978 /* Overlay.png in Resources */, 1A4C631517380272001E0978 /* Overlay@2x.png in Resources */,