//
// EncodeViewController.m
// demoGifLib
//
// Created by soleilpqd on 10/28/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "EncodeViewController.h"
#import
#import
#import
@interface EncodeViewController() {
NSArray *_items;
UIView *_vwLock;
UIActivityIndicatorView *_indicator;
ALAssetsLibrary *_assetsLibrary;
}
@property(nonatomic, strong)NSMutableArray *listImages;
@property(nonatomic, strong)NSArray *items;
- ( void )showLockView;
- ( void )dismissLockView;
@end
@implementation EncodeViewController
- ( void )showLockView {
if ( _vwLock == nil ) {
_vwLock = [[ UIView alloc ] initWithFrame:self.view.bounds ];
_indicator = [[ UIActivityIndicatorView alloc ] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge ];
_vwLock.backgroundColor = [[ UIColor blackColor ] colorWithAlphaComponent:0.5 ];
_indicator.center = CGPointMake( _vwLock.bounds.size.width / 2, _vwLock.bounds.size.height / 2 );
[ _vwLock addSubview:_indicator ];
}
[ self.view addSubview:_vwLock ];
[ _indicator startAnimating ];
}
- ( void )dismissLockView {
[ _vwLock removeFromSuperview ];
[ _indicator stopAnimating ];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
_items = [[ NSFileManager defaultManager ] contentsOfDirectoryAtPath:[[[ NSBundle mainBundle ] bundlePath ] stringByAppendingPathComponent:@"frames" ]
error:NULL ];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait( interfaceOrientation );
}
- ( void )dealloc {
// [ _items release ];
// if ( _vwLock ) {
// [ _vwLock release ];
// [ _indicator release ];
// }
// [ super dealloc ];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _items.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *s = [ _items objectAtIndex:indexPath.row ];
cell.textLabel.text = s.stringByDeletingPathExtension;
NSBundle *bundle = [ NSBundle bundleWithPath:[[[ NSBundle mainBundle ] bundlePath ] stringByAppendingFormat:@"/frames/%@", s ]];
cell.imageView.image = [ UIImage imageWithContentsOfFile:[ bundle pathForResource:@"0" ofType:@"png" ]];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[ tableView deselectRowAtIndexPath:indexPath animated:YES ];
NSString *s = [ _items objectAtIndex:indexPath.row ];
NSBundle *bundle = [ NSBundle bundleWithPath:[[[ NSBundle mainBundle ] bundlePath ] stringByAppendingFormat:@"/frames/%@", s ]];
NSArray *arr = [[ NSFileManager defaultManager ] contentsOfDirectoryAtPath:bundle.bundlePath
error:NULL ];
UIAlertView *alert = [[ UIAlertView alloc ] initWithTitle:@"Encode confirm"
message:[ NSString stringWithFormat:@"Encode %i frames of "%@"?", arr.count, s.stringByDeletingPathExtension ]
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil ];
alert.tag = indexPath.row;
[ alert show ];
// [ alert release ];
}
- ( void )alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ( buttonIndex ) {
[ self showLockView ];
[ self performSelectorInBackground:@selector( startEncodeWithBundleName: )
withObject:[ _items objectAtIndex:alertView.tag ]];
}
}
- (NSArray *)findGIFImageInNormal:(NSString *)gifName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// NSString *strFile = [documentsDirectory stringByAppendingPathComponent:@"hello/config.plist"];
// NSLog(@"strFile: %@", strFile);
NSString *strPath = [documentsDirectory stringByAppendingPathComponent:@"Normal"];
if (![[NSFileManager defaultManager] fileExistsAtPath:strPath]) {
NSLog(@"there is no Directory: %@",strPath);
// [[NSFileManager defaultManager] createDirectoryAtPath:strPath withIntermediateDirectories:YES attributes:nil error:nil];
}
//取得当前目录下的全部文件
// NSFileManager *fileManage = [NSFileManager defaultManager];
// NSArray *file = [fileManage subpathsOfDirectoryAtPath:strPath error:nil];
// NSArray *file = [self getFilenamelistOfType:@"png" fromDirPath:strPath];
NSArray *file = [self getFilenamelistOfType:@"png" fromDirPath:strPath GIFName:gifName];
// NSLog(@"the file is %@", file);
return file;
}
-(NSArray *) getFilenamelistOfType:(NSString *)type fromDirPath:(NSString *)dirPath GIFName:(NSString *)gifName
{
NSArray *tempList = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:dirPath error:nil]
pathsMatchingExtensions:[NSArray arrayWithObject:type]];
NSMutableArray *fileList = [NSMutableArray array];
for (NSString *fileName in tempList) {
// NSString *name = [[fileName componentsSeparatedByString:@"."] objectAtIndex:0];
// if ([fileName isEqualToString:gifName] ) {
[fileList removeObject:fileName];
// [fileList addObject:fileName];
// }
if ([fileName rangeOfString:gifName].location != NSNotFound) {
// if ([fileName rangeOfString:gifName] ) {
// [fileList removeObject:fileName];
[fileList addObject:fileName];
}
// NSLog(@"fileName is %@", name);
}
tempList = nil;
// //block比较方法,数组中可以是NSInteger,NSString(需要转换)
// NSComparator finderSort = ^(id string1,id string2){
//
// if ([string1 integerValue] > [string2 integerValue]) {
// return (NSComparisonResult)NSOrderedDescending;
// }else if ([string1 integerValue] 0) {
UIImage *image = [_listImages objectAtIndex:0];
// UIImageWriteToSavedPhotosAlbum(image, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);
NSLog(@"the remain image count is %lu", (unsigned long)_listImages.count);
[_assetsLibrary writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)image.imageOrientation completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
NSLog(@"%@", [error description]);
NSLog(@"Save image fail:%@",error);
}else{
NSLog(@"Save image succeed.");
[_listImages removeObjectAtIndex:0];
NSLog(@"one image saved");
[self saveNext];
}
}];
}
else {
[self allDone];
}
}
-(void) savedPhotoImage:(UIImage*)image didFinishSavingWithError: (NSError *)error contextInfo: (void *)contextInfo {
if (error) {
//NSLog(@"%@", error.localizedDescription);
// [error description]
NSLog(@"%@", [error description]);
}
else {
[_listImages removeObjectAtIndex:0];
NSLog(@"one image saved");
}
[self saveNext];
}
- (void)allDone
{
NSLog(@"allDone --###");
}
- ( void )showError:( int )errCode {
UIAlertView *alert = [[ UIAlertView alloc ] initWithTitle:@"Error while encode"
message:[ giflib_ios getErrorDescription:errCode ]
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil ];
[ alert show ];
// [ alert release ];
[ self performSelectorOnMainThread:@selector( dismissLockView )
withObject:nil
waitUntilDone:NO ];
}
@end
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17672 Accepted Su…