Move,rotate and scale UIImages, then merge them! in iphone - ios

rotate image merge but not working in this code
i post my code
please give me solution
- (void)mergeImage :(UIImage *)imageA withImage:(UIImage *)imageB ###
{
UIImage *image0 = imageA;
UIImage *image1=overlayimg.image;
CGSize newImageSize = CGSizeMake(overlayimg.frame.size.width, overlayimg.frame.size.height);
UIGraphicsBeginImageContext(newImageSize);
[image0 drawInRect:CGRectMake(overlayimg.frame.origin.x,overlayimg.frame.origin.y,newImageSize.width,newImageSize.height)];
NSLog(#"Last Rotation:%f",templastrotate);
overlayimg.transform = CGAffineTransformMakeRotation(templastrotate);
CGContextConcatCTM(UIGraphicsGetCurrentContext(), overlayimg.transform);
[image1 drawInRect:CGRectMake(overlayView.frame.origin.x, overlayView.frame.origin.y,overlayView.frame.size.width,overlayView.frame.size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
imageView.contentMode = UIViewContentModeScaleAspectFill & UIViewContentModeScaleAspectFit;
imageView.image=newImage;
UIGraphicsEndImageContext();
}

Related

Change size of UIImage to desired size

I am using this code to change the size of images.
- (UIImage *)scaledImage:(UIImage *)image size:(CGSize)size {
UIGraphicsBeginImageContextWithOptions(size, NO, 1.0);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
I am currently in need to change the size of 100 images at runtime but this code causes delay. The loading time is much.
Is there any faster way to resize the UIImage?
Thanks
try this code :
CGRect rect = CGRectMake(0,0,75,75);
UIGraphicsBeginImageContext( rect.size );
[yourCurrentOriginalImage drawInRect:rect];
UIImage *picture1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(picture1);
UIImage *img=[UIImage imageWithData:imageData];
'- (UIImage *)scaledImage:(UIImage *)image size:(CGSize)size {
CGRect rect = CGRectMake(0,0, size.width,size.height);
UIGraphicsBeginImageContext( size );
[image drawInRect:rect];
UIImage *picture1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(picture1);
UIImage *img=[UIImage imageWithData:imageData];
return img;
}'

How to get circular image in an imageview ios7

How can i get a circular image from a UIImage and display it on an image view.The image should be like the one displayed in IOS7 call History
- (UIImage *)getRoundedRectImageFromImage :(UIImage *)image onReferenceView :
(UIImageView*)imageView withCornerRadius :(float)cornerRadius
{
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0);
[[UIBezierPath bezierPathWithRoundedRect:imageView.bounds
cornerRadius:cornerRadius] addClip];
[image drawInRect:imageView.bounds];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return finalImage;
} And call the method like this
imageView.image = [self getRoundedRectImageFromImage:image
onReferenceView:
imageView withCornerRadius:imageView.frame.size.width/2];
imageView.clipsToBounds=YES;
imageView.layer.masksToBounds = YES;

iOS : How to get image with specific size from AssetsLibrary

I am in trouble with my App and expecting your help. I want to upload photo with specific size**(1200*1800)** from library to server,and I need to get original image then compress it.
UIImage *image = [UIImage imageWithCGImage:[asset fullResolutionImage] scale:[asset scale] orientation:0];
Unfortunately my app will get crashed if the original image size is large than 20M. So is there any way to get the image with specific size from AssetsLibrary directly?
I just Put some Helpful code, i am not sure but might be helpful in your case:
For Get Crop Image:
UIImage *croppedImg = nil;
CGRect cropRect = CGRectMake(AS YOu Need);
croppedImg = [self croppIngimageByImageName:self.imageView.image toRect:cropRect];
Use following method that return UIImage (as You want size of image)
- (UIImage *)croppIngimageByImageName:(UIImage *)imageToCrop toRect:(CGRect)rect
{
//CGRect CropRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height+15);
CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}
Here you get Croped Image that return by above method;
OR RESIZING
And also Use following method for specific hight and width with image for Resizing UIImage:
+ (UIImage*)resizeImage:(UIImage*)image withWidth:(int)width withHeight:(int)height
{
CGSize newSize = CGSizeMake(width, height);
float widthRatio = newSize.width/image.size.width;
float heightRatio = newSize.height/image.size.height;
if(widthRatio > heightRatio)
{
newSize=CGSizeMake(image.size.width*heightRatio,image.size.height*heightRatio);
}
else
{
newSize=CGSizeMake(image.size.width*widthRatio,image.size.height*widthRatio);
}
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
This method return NewImage, with specific size that you want.

Creating Thumbnail from Video - Improving Speed Performance via MPMoviePlayerController

This is my code by which is i am using. I want to generate thumbnail after that i create a video via these thumbnail with drawing which is done on "drawImage" UIImageView.
while([self.thunbnailArray count])
{
id times = [self.thunbnailArray objectAtIndex:0];////self.thumbnailArray contains duratin of player at which thumbnail generate//////
[self.thunbnailArray removeObjectAtIndex:0];
UIImage* thumbnail = [player1 thumbnailImageAtTime:[times floatValue] timeOption:MPMovieTimeOptionExact];
UIGraphicsBeginImageContext(drawImage.frame.size);////drawImage is a UIImageView to make drawing
[drawImage.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef firstImageRef = thumbnail.CGImage;/////merge thumbnail and drawing both together
CGFloat firstWidth = CGImageGetWidth(firstImageRef);
CGFloat firstHeight = CGImageGetHeight(firstImageRef);
CGSize mergedSize = CGSizeMake(firstWidth, firstHeight);
UIGraphicsBeginImageContext(mergedSize);
[thumbnail drawInRect:CGRectMake(0, 0, firstWidth, firstHeight)];
[viewImage drawInRect:CGRectMake(0, 0, firstWidth, firstHeight)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.imageArray addObject:newImage];///self.imageArray used to generate video
}

Combining images not working in device iOS

I am trying to combine two images into one. This is the code I am using:
UIImage* image1 = [UIImage imageNamed:#"1.tif"];
UIImage* image2 = [UIImage imageNamed:#"sign.tif"];
UIGraphicsBeginImageContext(image1.size);
[image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];
[image2 drawInRect:CGRectMake(0, 0, image2.size.width, image2.size.height)];
UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageView1.image = combinedImage;
It works perfectly in the simulator but does not work on the device. I get a white screen. Can any one please help me with this.
Any help will be appreciated.
Try to use this function:
- (UIImage * ) mergeImage: (UIImage *) imageA
withImage: (UIImage *) imageB
strength: (float) strength {
UIGraphicsBeginImageContextWithOptions(CGSizeMake([imageA size].width,[imageA size].height), NO, 0.0);
[imageA drawAtPoint: CGPointMake(0,0)];
[imageB drawAtPoint: CGPointMake(0,0)
blendMode: kCGBlendModeNormal // you can play with this
alpha: strength]; // 0 - 1
UIImage *mergedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return mergedImage;
}
And call it like this:
UIImage* image1 = [UIImage imageNamed:#"1.tif"];
UIImage* image2 = [UIImage imageNamed:#"sign.tif"];
UIImage *mergedImage =[self mergeImage:image1 withImage:image2 strength:1];

Resources