STEP 1
WRITE IT IN TO "ViewController.h"
#import <UIKit/UIKit.h>
#import "ZDStickerView.h"
@interface ViewController : UIViewController<ZDStickerViewDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property (strong, nonatomic) IBOutlet UIImageView *ImgViewMain;
@property (strong, nonatomic) IBOutlet UIButton *btnImage2;
@end
STEP 2
WRITE IT IN TO "ViewController.m"
#import "ViewController.h"
@interface ViewController ()
{
ZDStickerView *userResizableView1;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnAdd:(id)sender
{
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.allowsEditing = YES;
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imgPicker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
{
UIImage *imgChosen = info[UIImagePickerControllerEditedImage];
CGRect gripFrame1 = CGRectMake(90, 50, 100, 100);
UIImageView *imageView1 = [[UIImageView alloc] initWithImage:imgChosen];
UIView* contentView = [[UIView alloc] initWithFrame:gripFrame1];
[contentView addSubview:imageView1];
userResizableView1 = [[ZDStickerView alloc] initWithFrame:gripFrame1];
userResizableView1.delegate = self;
userResizableView1.contentView = contentView;//UIview;
[self.view addSubview:userResizableView1];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)btnDone:(id)sender
{
UIImageWriteToSavedPhotosAlbum([self saveGLScreenshotToPhotosAlbum:_ImgViewMain.image],nil,nil,nil);
}
- (UIImage *)cropImage:(UIImage *)oldImage
{
NSLog(@"subviews=%@",self.view.subviews);
CGSize imageSize = oldImage.size;
UIGraphicsBeginImageContextWithOptions(CGSizeMake( imageSize.width,imageSize.height -50),NO,0.);
[oldImage drawAtPoint:CGPointMake( 0, -50) blendMode:kCGBlendModeCopy alpha:1.];
UIImage *croppedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return croppedImage;
}
- (UIImage *)saveGLScreenshotToPhotosAlbum:(UIImage *)oldImage
{
for (UIView *zdobj in self.view.subviews)
{
if ([zdobj isKindOfClass:[ZDStickerView class]]) {
for (UIView *viewObj in zdobj.subviews)
{
if (viewObj.tag==99 || viewObj.tag==100)
{
[viewObj removeFromSuperview];
}
}
}
}
UIGraphicsBeginImageContext(self.view.bounds.size);
// retrieve the current graphics context
CGContextRef context = UIGraphicsGetCurrentContext();
// render view into context
[self.view.layer renderInContext:context];
// create image from context
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
image=[self cropImage:image];
UIGraphicsEndImageContext();
return image;
}
@end
STEP 3
ATTECH LIBRARY
1) Download Library from link which is given below.
2) Add this folder in your main program.
SETP 4
SOLVE UNEXPECTED YOUR ERROR BY YOUR SELF
BEST OF LUCK
No comments:
Post a Comment