Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone:-simplest way to crop image of desired shape and size

Tags:

xcode

iphone

i am trying to crop image according to my desire....for my cinemagram type app.....and use it in my application

i have tried a lot of options but none of tham is...usefull for me i read answers on stack over flow but of no use

plzz help me out

image = [UIImage imageNamed:@"images2.jpg"];
imageView = [[UIImageView alloc] initWithImage:image];

CGSize size = [image size];

[imageView setFrame:CGRectMake(0, 0, size.width, size.height)];
[[self view] addSubview:imageView];
[imageView release];    

thanks

like image 716
swetank Avatar asked May 24 '12 06:05

swetank


Video Answer


1 Answers

Here is the exact code to resize your image to desired size

    CGSize itemSize = CGSizeMake(320,480); // give any size you want to give

    UIGraphicsBeginImageContext(itemSize);

    CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);

    [myimage drawInRect:imageRect];


    myimage = UIGraphicsGetImageFromCurrentImageContext();  

    UIGraphicsEndImageContext();

Now my image is of your desired size

like image 71
Dinesh Kaushik Avatar answered Nov 16 '22 00:11

Dinesh Kaushik