Join multiple cropped images to form a single image in iOS - iphone

I have cropped multiple images from a bigger image, now I have to join these cropped images to form a new image which can be loaded into a single imageview.

What you need to do is create an image context, draw your images into this context, then convert this context to an image.
//create context
CGSize endImageSize = CGSizeMake(128.0, 128.0);
UIGraphicsBeginImageContext(endImageSize);
// draw images into this context
[anImage drawInRect:CGRectMake(0,0,64, 64)];
[anotherImage drawInRect:CGRectMake(64, 64, 64, 64)];
//convert context into a UIImage
UIImage *endImage = UIGraphicsGetImageFromCurrentImageContext();
//cleanup
UIGraphicsEndImageContext();
That being said, it is probably better to just make a UIImageView for each image.

Related

Crop an image to make a process on the result

I want to recognise the text written in an image, So what I want is to crop this image to make the process on the desired part only not all the image.
So any idea how can I do this ?
Here is the code am using on the image:
NSString*ret= [self DoProcess:capturedImage];
Here is I want to crop the captured image to make the process on it.
You can define a CGRect for the part of image you want to extract and then use the below method:
CGRect cropRect = ...;
UIImage *cropped = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([fullImage CGImage], cropRect) scale:fullImage.scale orientation:fullImage.imageOrientation];

Crop image after taking image from camera

My question is that I want to add crop image functionality in my pocketWallet app. I want to take image from camera and save it in ImageView after that i want to crop that image. I have read many questions like same but it Unfotunatly not found required answer.
Please tell me how can I change imageview size with exact image size that i take from camera.
I am using a uiview to crop the specific part of the image . But when I cropped the image then not get exact part which I want to crop. My cropped image code is below,
-(UIImage *)cropImage{
float tempx=CGRectGetMinX(cropedAngle.frame);
float tempy=CGRectGetMinY(cropedAngle.frame);
CGRect rect=CGRectMake(tempx, tempy, 320, 200);
CGImageRef image = [imgView.image CGImage];
CGImageRef imageRef = CGImageCreateWithImageInRect(image,rect);
UIImage *imge = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
// Create and show the new image from bitmap
return imge;
}
First of tell my logic is right or not to crop image? In which this code cropedAngle is my uiview which i used to crop the specific part of image .
Where am I wrong?

How to create a new image from an existing image and a string over it

I need to create something like:
http://t3.gstatic.com/images?q=tbn:ANd9GcQZu06WspVUaFTn-C-YD6Pzu_oWH5NLA1Q8nPUZEdemllFIAMNn
So I need to place a user input string over an image in a specified spot, then save it in the memory.
How can I do it?
Create a new bitmap image context. See this for help creating-and-drawing-on-a-new-uiimage
Draw your UIImage in drawInRect
Create black, rounded and transparent image. See this for help:
resize-a-uiimage-the-right-way
Draw black image drawInRect
Draw your NSString text. see this for help how-to-display-text-using-quartz-on-the-iphone drawInRect or drawInPoint
Here is a small code example for cropping an image.
- (UIImage *)croppedImageWithRect:(CGRect)bounds {
CGImageRef imageRef = CGImageCreateWithImageInRect(scaleImage.CGImage, bounds);
UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return croppedImage;
}
Enjoy.
use a UItextView over an image to show such string.

reduce image size in image view in iphone application

I need to reduce image size in iphone.
I found sending programmatically email in google,But did n't found clear info regarding reduce size of image view.
Can any one pls post some sample code.
Thank u in advance.
you can do it like:
UIImage* newImage = nil;
UIGraphicsBeginImageContext(newFrame); // this will crop
[sourceImage drawInRect:newFrame];
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
This will draw the image in the frame you specified. Now if you want to maintain the aspect ratio also you can have look at Maintain the aspect ratio of an image?
As I saw that you are using image view, so don't use first part of code I mentioned. Now you have to do only:
[imageView setContentMode:UIViewContentModeScaleAspectFit];
Do you mean scaling a view that an image is contained within, or do you mean you want to resample image data to make an image with a smaller file size?
First couple of results in google bring up this... Resize Image
Instead take UIButton and set the image as its backgroundImage property... It will automatically resize the image to the size of the button.
-(UIImage*)createThumbNailImage:(UIImage*)myThumbNail:(float)width:(float)height
{
// begin an image context that will essentially "hold" our new image
UIGraphicsBeginImageContext(CGSizeMake(width,height));
// now redraw our image in a smaller rectangle.
[myThumbNail drawInRect:CGRectMake(0.0, 0.0, width, height)];
// make a "copy" of the image from the current context
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return [newImage autorelease];
}
hAPPY iCODING...

UIViewContentModeScaleAspectFit iphone sdk gives poor quality image

Hopefully a quick one? I am creating a custom uitableviewcell and have added an imageview.
I have some PNG images which are around 200x200 in size. I want to create a thumbnail to put in the tableview, but when I resize the image, it results in a poor quality image.
I use UIViewContentModeScaleAspectFit to resize it to a 50x50 frame.
Should I be calling a better draw resize on each image before I Put it to the table cell? There will be around 20-40 images in each table, so I don't want to over work the device!!
Thanks for any help.
Rescaling the images yourself with CoreGraphics will give you more control over the quality, but your best bet is to size the images appropriately for your table in the first place -- less work the software has to do and complete control over the image's appearance.
If you still want to resize them in Quartz, here's one way you might go about it:
UIImage* originalThumbnail = [UIImage imageWithContentsOfFile:<PATH_TO_IMAGE>];
CGSize originalSize = [originalThumbnail size];
CGSize cropSize = { 50, 50 };
CGRect cropRect = CGRectMake(abs(cropSize.width - originalSize.width)/2.0, abs(cropSize.height - originalSize.height)/2.0, cropSize.width, cropSize.height);
CGImageRef imageRef = CGImageCreateWithImageInRect([originalThumbnail CGImage], cropRect);
// here's your cropped UIImage
UIImage* croppedThumbnail = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
You'd want to do this once if possible, i.e. not every time you construct your UITableViewCell.