I have to perform some image editing operation like cropping, gray scale, rotating
image, Polaroid-effects etc.
From these I found some of functionality like cropping, gray scale. But from this we have to manage separate functions iN there. Is there any valid API or Library available for iPhone to perform image processing?
I use the following function for cropping:
-(UIImage *)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect
{
CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect);
UIImage *cropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return cropped;
}
for this I have not idea, how to set cropping rectangle on my actual image...and how to re-size that rectangle.
Is there any method in iPhone like Android we direct crop image after capture image... by setting it`s some property we can achieve this in iPhone.
for gray scale I found something here, but for this if we perform Polaroid effect we have to manage separate enums...,
I found one Image Magik API for this but many people said apple reject app due to private API.and also not get how to use it.
If for this or any-other API available than tell me about it and its tutorial.
check the Quartz Demo code sample by apple... especially QuartzClippingView and QuartzMaskingView...
and if you want to learn core graphics basics for image editing, a quick look at Quartz 2D Programming Guide and Drawing and Printing Guide would really help...
also, if you are planning to go for better cropping check Cropped Image .. this is for mac but it can be useful for creating similar implementation for iPhone by using Cocoa Touch counterparts of the same classes they have used e.g. instead of NSBezierPath for mac use UIBezierPath for iPhone ...
No , Using ImageMagick is absolutely valid.
Pl. follow this discussion.
Related
Is there a way to apply some functions like:brightness,contrast,sharpness,hue,saturation,exposure to uiimages. For example I have a UIImageview and inside that i have a uiimage. I want to manipulate its brightness or contrast or sharpness with a help of UISlider
Have a look at the sample app GLImageProcessing, however it uses openGL to do the image processing, but it is really fast.
I've been using Core Plot to draw some charts for an iOS app I've been developing. While core plot is excellent as a charting application, it's a performance hog when it comes to any kind of user interaction. To get around this, I started doing a lot of the following:
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I would then swap out the view for the image of the view before starting my animations, which made them far smoother.
Since then, I've started using this idea more in my app. I haven't had much iOS experience before this project and haven't really looked at much source from more expert developers. I just wanted to look for some feedback - am I missing the point by taking this approach?
I use this extensively in an OpenGLES animation framework I've been working on to render animations between views. I don't know that you're missing the point, but if you are, then I must be as well, as so long as it fits within what you want to do in your application, it seems to me like a good way to go about doing things.
I've been struggling with this for awhile now, since there is little documentation on the subject. I have a UIImagePickerController in my iPhone application that I use to select an image to be applied as the background of a view later. This is easy enough to do. Unfortunately, if a user selects a large image from their camera roll it needs to be resized and cropped in order to look decent.
It's easy enough to toggle picker.allowsEditing to YES and get the image editor up, but the default crop dimensions are too small. I need to set it to the full dimensions of the iPhone screen (320 for the old models, 640 for the new). How do you do that? I've been Googling and looking at Apple's documentation, but I can't find anything. The best I found is a slightly buggy solution from 2009 (http://blog.stormyprods.com/2009/06/image-picker-sample.html) that almost works, but it shifts the image down about 20px. (Plus, it's a bit over-complicated.) Surely there's an elegant, simple solution that I'm missing?
One year later - Hi, like you, i haven't found anything useful, so i created this Project
- a custom size crop and zoom editing UIImagePicker Popover for the iPad.
You could easily change it for the iphone, hope that helps someone.
Here it is - https://github.com/yogev77/UIImagePickerWithEditor
May be this should work :
-(UIImage *)imageWithImage:(UIImage *)image CovertToSize:(CGSize)size {
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return destImage;
}
I want to show some images as a thumbnail in View controller but i dont know how to do this. Can anyone please give me some ideas or sample code if possible.
Are you asking how to create thumbnails from larger images, or about how to build a view controller which displays them nicely?
Building a view controller:
You could use TTPhotoViewController from the Three20 project (description), which acts similarly to the iPhone's built in camera roll to view images.
You can look at the Scrolling sample code from apple, referred to in this question about using it for thumbnails.
If you want to build one yourself, you might consider using a GridView from the moriarty library, either as a large grid in a UIScrollView, or on a more efficient row-by-row basis in a UITableView. There's a previous question on optimized image loading in a UIScrollView.
Creating thumbnails from larger images:
The code-easiest way to scale down an image is to simply display it in a UIImageView with a frame set to the smaller size that you want - it's scaled for you.
If you want to save a thumbnail, or care about memory usage, you can create a hard-scaled version. The sample code below is taken from this blog post, and can be added to UIImage as a category method:
- (UIImage*) imageScaledToSize: (CGSize) newSize {
UIGraphicsBeginImageContext(newSize);
[self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Finally, here's a previous question on masking out round corners on an image, similar to the app icons used on the home screen.
Added
Using an image's built-in thumbnail:
There's a nice function called CGImageSourceCreateThumbnailAtIndex that understands built-in thumbnails in certain image data formats. You can see some useful sample code for this under Creating a Thumbnail Image from an Image Source in the Image I/O Programming Guide from Apple.
There are multiple issues with thumbnails; perhaps you could clarify which ones you are most concerned about?
How to display a smaller version of an existing image
How to speed up paging by caching the thumbnails (instead of just dynamically shrinking the originals)
How to allow the user to page through the thumbnails
How to synchronize the thumbnails with the originals, in the event that your images are editable or the user can add to them
I'm using a whole bunch of CALayers, creating a tile-based image not unlike GoogleMaps (different versions of the same image with more/less detail).
The code I'm using to do this is:
UIImage* image = [self loadImage:obj.fileName zoomLevel:obj.zoomLevel];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
obj.layerToAddTo.contents = [image CGImage];
[CATransaction commit];
I don't really feel like loading the CGImage from file using CoreGraphics because I'm lazy. But I will if there's a big performance boost! LoadImage just mangles a string to get the right path for loading said image, and obj is a NSObject-struct that holds all the info I need for this thread.
Help?
There's not a big performance boost - if anything it's the other way around. By going throuh UIImage to load up your images, you'll get all the benefits of caching that it does for you and it'll be a very speedy critter to use with your various CALayers.
I just tried this and using pure CoreGraphics to load the image rather than using UIImage gave a noticeable speed improvement when loading many images in one go.
"I just tried this and using pure CoreGraphics to load the image rather than using UIImage gave a noticeable speed improvement when loading many images in one go."
How did you avoid using a UIImage? Or more precisely, how do you load an image file directly into CoreGraphics without going through a UIImage?
One reason why NOT to use UIImage -imageNamed: to load images is that they are stored in the internal cache and that cache is not cleared in low memory situation.
I don't have a definite answer but I'd guess that you'd see a slower load time when using UIImage than you'd see when using CGImage. With CGImage, you specify the image type (jpg or png) during creation, but with UIImage, the object type needs to be determined dynamically. Admittedly, this is probably as simple as looking at the first few bytes of the image file, but it might not be.
Once the image is actually in use, I wouldn't imagine that there'd be any difference at all between using the CGImage that internally represents a UIImage vs. using a CGImage you created yourself. I'd think they'd be exactly equivalent.