Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MyViewController.h
- #import <UIKit/UIKit.h>
- #import <wand/MagickWand.h>
- @interface MyViewController : UIViewController
- @property (retain, nonatomic) IBOutlet UIImageView *imageView;
- @property (retain, nonatomic) MagickWand *wand;
- @end
- // MyViewController.m
- #import "MyViewController.h"
- @implementation MyViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- MagickWandGenesis();
- self.wand = NewMagickWand();
- [self drawMonochromeImage:@"logo:"];
- }
- -(void)drawMonochromeImage:(NSString *)filePath
- {
- // Create temporary file
- NSString *tempFilePath = [NSTemporaryDirectory()
- stringByAppendingPathComponent:@"logo.jpg"];
- // Read given image with C-string
- MagickReadImage(self.wand,
- [filePath cStringUsingEncoding:NSASCIIStringEncoding]
- );
- // Monochrome image
- MagickQuantizeImage(self.wand,2,GRAYColorspace,1,MagickFalse,MagickFalse);
- // Write to temporary file
- MagickWriteImage(self.wand,
- [tempFilePath cStringUsingEncoding:NSASCIIStringEncoding]
- );
- // Load UIImage from temporary file
- UIImage *imgObj = [UIImage imageWithContentsOfFile:tempFilePath];
- // Display on device
- [self.imageView setImage:imgObj];
- [self.imageView setContentMode:UIViewContentModeScaleAspectFit];
- }
- -(void)viewDidUnload
- {
- // Clean-up
- if (self.wand)
- self.wand = DestroyMagickWand(self.wand);
- MagickWandTerminus();
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement