Created
November 12, 2012 13:43
-
-
Save imrekel/4059462 to your computer and use it in GitHub Desktop.
bme-ios - PhotoOrganizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)handlePhotoLongPress:(UIGestureRecognizer*)sender | |
{ | |
if (sender.state == UIGestureRecognizerStateBegan) | |
{ | |
_selectedPhoto = (POPhotoView*)sender.view; | |
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"Műveletek" | |
delegate:self | |
cancelButtonTitle:@"Mégsem" | |
destructiveButtonTitle:nil | |
otherButtonTitles:@"Forgatás balra", @"Forgatás jobbra", @"Szürkeárnyalatos", nil]; | |
[actionSheet showFromRect:sender.view.frame inView:self.view animated:YES]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)handlePhotoTap:(UITapGestureRecognizer*)sender | |
{ | |
POPhotoView* photo = (POPhotoView*)sender.view; | |
[photo removeFromSuperview]; | |
[self.view addSubview:photo]; | |
if (photo.isExpanded) | |
{ | |
photo.isExpanded = NO; | |
photo.bounds = photo.originalBounds; | |
photo.center = photo.originalCenter; | |
} | |
else | |
{ | |
photo.originalBounds = photo.bounds; | |
photo.originalCenter = photo.center; | |
photo.isExpanded = YES; | |
CGPoint center = CGPointMake( | |
self.view.bounds.size.width / 2, photo.center.y); | |
if (center.y < photo.bounds.size.height * 1.5) | |
center.y = photo.bounds.size.height * 1.5 + kPhotoPadding; | |
photo.center = center; | |
photo.bounds = CGRectMake(0, 0, photo.bounds.size.width * 3, | |
photo.bounds.size.height * 3); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)performOnAllPhotosAnimated:(void (^)(POPhotoView* photo))photoOperation | |
{ | |
for (UIView* view in self.view.subviews) | |
{ | |
if ([view isKindOfClass:[POPhotoView class]]) | |
{ | |
[UIView animateWithDuration:0.5 delay:0 | |
options:UIViewAnimationOptionCurveEaseInOut | | |
UIViewAnimationOptionLayoutSubviews | |
animations:^{ | |
photoOperation((POPhotoView*)view); | |
} completion:nil]; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (UIImage*)transformImageToGrayScale:(UIImage*)image | |
{ | |
CGContextRef ctx; | |
CGImageRef imageRef = [image CGImage]; | |
NSUInteger width = CGImageGetWidth(imageRef); | |
NSUInteger height = CGImageGetHeight(imageRef); | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
unsigned char *rawData = malloc(height * width * 4); | |
NSUInteger bytesPerPixel = 4; | |
NSUInteger bytesPerRow = bytesPerPixel * width; | |
NSUInteger bitsPerComponent = 8; | |
CGContextRef context = CGBitmapContextCreate(rawData, width, height, | |
bitsPerComponent, bytesPerRow, colorSpace, | |
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); | |
CGColorSpaceRelease(colorSpace); | |
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); | |
CGContextRelease(context); | |
int byteIndex = 0; | |
for (int ii = 0 ; ii < width * height ; ++ii) | |
{ | |
int outputColor = (rawData[byteIndex] + rawData[byteIndex+1] + | |
rawData[byteIndex+2]) / 3; | |
rawData[byteIndex] = (char) (outputColor); | |
rawData[byteIndex+1] = (char) (outputColor); | |
rawData[byteIndex+2] = (char) (outputColor); | |
byteIndex += 4; | |
} | |
ctx = CGBitmapContextCreate(rawData, | |
CGImageGetWidth( imageRef ), | |
CGImageGetHeight( imageRef ), | |
8, | |
CGImageGetBytesPerRow( imageRef ), | |
CGImageGetColorSpace( imageRef ), | |
kCGImageAlphaPremultipliedLast ); | |
imageRef = CGBitmapContextCreateImage (ctx); | |
UIImage* rawImage = [UIImage imageWithCGImage:imageRef]; | |
CGContextRelease(ctx); | |
free(rawData); | |
return rawImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment