Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // MyViewController.h
  2. #import <UIKit/UIKit.h>
  3. #import <wand/MagickWand.h>
  4.  
  5. @interface MyViewController : UIViewController
  6.  
  7. @property (retain, nonatomic) IBOutlet UIImageView *imageView;
  8. @property (retain, nonatomic) MagickWand *wand;
  9.  
  10. @end
  11.  
  12. // MyViewController.m
  13. #import "MyViewController.h"
  14.  
  15. @implementation MyViewController
  16.  
  17. - (void)viewDidLoad
  18. {
  19. [super viewDidLoad];
  20. MagickWandGenesis();
  21. self.wand = NewMagickWand();
  22. [self drawMonochromeImage:@"logo:"];
  23. }
  24.  
  25. -(void)drawMonochromeImage:(NSString *)filePath
  26. {
  27. // Create temporary file
  28. NSString *tempFilePath = [NSTemporaryDirectory()
  29. stringByAppendingPathComponent:@"logo.jpg"];
  30.  
  31. // Read given image with C-string
  32. MagickReadImage(self.wand,
  33. [filePath cStringUsingEncoding:NSASCIIStringEncoding]
  34. );
  35.  
  36. // Monochrome image
  37. MagickQuantizeImage(self.wand,2,GRAYColorspace,1,MagickFalse,MagickFalse);
  38.  
  39. // Write to temporary file
  40. MagickWriteImage(self.wand,
  41. [tempFilePath cStringUsingEncoding:NSASCIIStringEncoding]
  42. );
  43.  
  44. // Load UIImage from temporary file
  45. UIImage *imgObj = [UIImage imageWithContentsOfFile:tempFilePath];
  46.  
  47. // Display on device
  48. [self.imageView setImage:imgObj];
  49. [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
  50. }
  51. -(void)viewDidUnload
  52. {
  53. // Clean-up
  54. if (self.wand)
  55. self.wand = DestroyMagickWand(self.wand);
  56. MagickWandTerminus();
  57. }
  58.  
  59. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement