How To Enhance Image Processing With Core Image In IOS Apps

Core Image is a powerful framework for image processing and analysis technology designed to provide real-time processing for still and video images. This helps you easily apply filters to images, such as modifying the hue, exposure or vibrant. It uses the GPU or CPU rendering path to process the image data very fast.

Core Image can be chained with multiple filters to an Image or video frame at once by creating custom effects. Core Image provides us more than 90 built-in filters on iOS and over 120 on OS X. You can set up filters by supplying key-value pairs for a filter’s input parameters. You can use the output of one filter as the input of another filter, to create amazing effects.

Here is how the Core Image is related to the iOS operating system

core-image-1024x415

Before going into Core Image, let’s know about the classes used in the Core Image framework:

CIContext:

The CIContext is a class which provides an evaluation context for rendering a CIImage object. CIContext class is used to take advantage of the built-in Core Image filters while processing an image.

CIImage:

The CIImage is a class which represent an image or holds an image data which may be created from a UIImage, from an image file, or from pixel data.

CIFilter:

The CIFilter class produces a CIImage object as output. A filter takes one or more images as input. The filter class has a dictionary that defines the attributes,so the parameters of a CIFilter object are set and retrieved through the use of key-value pairs. This helps us to add some beautiful effect on the input image.

Sample example:

In this example local image path is used in resource file to apply effects.

// 1 Retrieving the localimage.png path from resource bundle

NSString *filePath =
  [[NSBundle mainBundle] pathForResource:@"localimage" ofType:@"png"];
NSURL *fileNameAndPath = [NSURL fileURLWithPath:filePath];

// 2 Converting the normal image to CIImage object by passing the URL of original localimage.png

CIImage *beginImage =
  [CIImage imageWithContentsOfURL:fileNameAndPath];

// 3 Adding the filter SepiaTone effect to the localimage.png

CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"
                              keysAndValues: kCIInputImageKey, beginImage,
                    @"inputIntensity", @0.8, nil];
CIImage *outputImage = [filter outputImage];

// 4 showing the output image in the UIImageView

IImage *newImage = [UIImage imageWithCIImage:outputImage];
self.imageView.image = newImage;

Note : Here we can change the value of the CIFilter value which is given 0.8 by using a slider which min value is 0 and max value is 1.

Here we have not used the CIContext to perform an CIFilter as said earlier. It helps us to make it easier.

Lets change the above code to include the CIContex:

CIImage *beginImage =
[CIImage imageWithContentsOfURL:fileNameAndPath];
 
// 1
CIContext *context = [CIContext contextWithOptions:nil];
 
CIFilter *filter = [CIFilter filterWithName:@"CISepiaTone"
keysAndValues: kCIInputImageKey, beginImage,
@"inputIntensity", @0.8, nil];
CIImage *outputImage = [filter outputImage];
 
// 2
CGImageRef cgimg =
[context createCGImage:outputImage fromRect:[outputImage extent]];
 
// 3
UIImage *newImage = [UIImage imageWithCGImage:cgimg];
self.imageView.image = newImage;
 
// 4
CGImageRelease(cgimg);

Let’s see what happened here:

Here we set up the CIContext object. The CIContext takes an NSDictionary that specifies options including the color format and whether the context should run on the CPU/GPU. Here the default values are fine and so you passed as nil for that argument.

Here we used an method on the context object to draw a CGImage. Calling this method createCGImage:fromRect: on the context with the supplied CIImage will give us an output as CGImageRef.

Next, we converted the CGImage to UIImage using “imageWithCGImage”.

At last we release the CGImageRef as CGImage. CGImage is a C API which need to free memory even it runs with ARC.

Note: To know about all available filters write the following code and call the method in viewDidLoad / onLaunch. The filters are written on the console log.

-(void)logAllFilters {
NSArray *properties = [CIFilter filterNamesInCategory:
kCICategoryBuiltIn];
NSLog(@"%@", properties);
for (NSString *filterName in properties) {
CIFilter *fltr = [CIFilter filterWithName:filterName];
NSLog(@"%@", [fltr attributes]);
}
}

Like this blog? I’d love to hear about your thoughts on this. Thanks for sharing your comments.

How To Make Static Framework IOS Device Independent?

In our previous post, we had mentioned the steps to create a Static Library or Framework for iOS. Here, we will illustrate the steps to make it device independent, i.e. the library can be used to develop app for all iOS devices, instead of recreating the code for each device.

Step 1: Create an Aggregate Target

  • Click File >> New Target and create a new Aggregate target in Other menu.

  • Name your aggregate target – like ‘Framework’

xcode_image

 Step 2: Adding the Static Library as a Dependent Target

  • Add the static library target to the ‘Target Dependencies’.

framework-image

Step 3: Build the ‘Other’ Platform

  • To build the ‘Other’ platform, use a ‘Run Script’ phase.

  • Add a new ‘Run Script’ build phase to your ‘Aggregate’ target and paste the following code.
set -e
 
set -e
 
set +u
 
# Avoid recursively calling this script.
 
if [[ $SF_MASTER_SCRIPT_RUNNING ]]
 
then
 
   exit 0
 
fi
 
set -u
 
export SF_MASTER_SCRIPT_RUNNING=1
 
  
 
SF_TARGET_NAME=${PROJECT_NAME}
 
SF_EXECUTABLE_PATH="lib${SF_TARGET_NAME}.a"
 
SF_WRAPPER_NAME="${SF_TARGET_NAME}.framework"
 
  
 
# The following conditionals come from
 
# https://github.com/kstenerud/iOS-Universal-Framework
 
  
 
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]
 
then
 
   SF_SDK_PLATFORM=${BASH_REMATCH[1]}
 
else
 
   echo "Could not find platform name from SDK_NAME: $SDK_NAME"
 
   exit 1
 
fi
 
  
 
if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]] then
 
   SF_SDK_VERSION=${BASH_REMATCH[1]}
 
else
 
   echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
 
   exit 1
 
fi
 
  
 
if [[ "$SF_SDK_PLATFORM" = "iphoneos" ]]
 
then
 
   SF_OTHER_PLATFORM=iphonesimulator
 
else
 
   SF_OTHER_PLATFORM=iphoneos
 
fi
 
  
 
if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$SF_SDK_PLATFORM$ ]]
 
then
 
   SF_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${SF_OTHER_PLATFORM}"
 
else
 
   echo "Could not find platform name from build products directory: $BUILT_PRODUCTS_DIR"
 
   exit 1
 
fi
 
  
 
# Build the other platform.
 
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}" -configuration "${CONFIGURATION}" -sdk ${SF_OTHER_PLATFORM}${SF_SDK_VERSION} BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}" $ACTION
 
  
 
# Smash the two static libraries into one fat binary and store it in the .framework
 
lipo -create "${BUILT_PRODUCTS_DIR}/${SF_EXECUTABLE_PATH}" "${SF_OTHER_BUILT_PRODUCTS_DIR}/${SF_EXECUTABLE_PATH}" -output "${BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/Versions/A/${SF_TARGET_NAME}"
 
  
 
# Copy the binary to the other architecture folder to have a complete framework in both.
 
cp -a "${BUILT_PRODUCTS_DIR}/${SF_WRAPPER_NAME}/Versions/A/${SF_TARGET

Step 4: Build to verify

  • Now  you have set up an environment to build a distributable <project_name>.framework

  • Build the ‘Aggregate’ target

  • Expand the Products group in X-Code, right click the static library and click ‘Show in Finder’

Note: If this doesn’t open Finder to show the static library, then try opening

~/Library/Developer/Xcode/DerivedData/<project name>/Build/Products/Debug-iphonesimulator/.

  • In this folder you will find your <project_name>.framework folder.

You can now share the <project_name>.framework among other iOS app developers.

How To Use “UIActionSheet” As A Pop-over View In Your IOS Apps

iOS-destructive_button

What is UIActionSheet

The action sheet in iOS contains a title and one or more buttons. Each of the buttons is associated with separate actions. It can be presented from a toolbar; tab bar, button bar item or from a view, however the title can be optional.

Why use UIActionSheet?

UIActionSheet is used in the following cases:

  • To show an option for a given task
  • To prompt the user to confirm an action
  • To get user input

Action sheet is dismissed by touching anywhere outside the pop-over.

How to use it?

  • Extend the UIActionSheetDeleagte in the .h header file of the ViewController
  • Then add a method named as”showActionSheet”

Example

[sourcecode]@interface MyViewController : UIViewController {

}

-(IBAction)showActionSheet:(id)sender;
@end[/sourcecode]

Initializing the UIActionSheet takes 5 following parameters

  •  initWithTitle
  • delegate
  • cancelButtonTitle
  • destructiveButtonTitle
  • otherButtonTitles

Add the following code in the .m file of viewcontroller.

Example

[sourcecode]-(IBAction)showActionSheet:(id)sender {
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"Set your title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive Button" otherButtonTitles:@"Rename",@"Delete", nil];

popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.view];
[popupQuery release];
}[/sourcecode]

How to know which button was clicked by user?

There is a delegate method named as “actionSheet clickedButtonAtIndex” in which you can get the action.

[sourcecode]-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

switch (buttonIndex) {
case 0:
NSLog(@”%@”,Destructive Button Clicked);
break;
case 1:
NSLog(@”%@”,Rename Button Clicked);
break;
case 2:
NSLog(@”%@”,Delete Button Clicked);
break;
case 3:
NSLog(@”%@”,Cancel Button Clicked);
break;
}
}[/sourcecode]

Conclusion:

UIActionSheet gives additional choices to the users for a particular action & gives a cleaner look to the app.

Guide To Display Images In Grid View On IPhone

In some iOS apps, displaying images in a single view would make the UI lose its uniformity. It would be difficult to manage images of different resolution and impossible to keep track of thousand of images without using Grid View in iPhone.

This is just like a “Grid View” application. Here we will explore how to display images, programmatically in “Grid view” on an iPhone.

Here We Go…

Step 1:

  • Open Xcode
  • Create a View base applicationGridview-123
  • Give the application name “ImageGrid”.

Step 2:

The directory structure is automatically created by the Xcode which also adds up essential frameworks to it. Now, explore the directory structure to check out the contents of the directory.

Step 3:

Here you need to add one ‘NSObject’ class to the project.

  • Select  project -> New File -> Cocoa Touch -> Objective-C class
  • Give the class name “Images”.

Step 4:

Then add an image to the project and give the image name “icon.png”.

Step 5:

  • Open “ImageGridViewController” file and add ‘UITableViewDelegate’ and ‘UITableViewDataSource’
  • Define ‘UITableView’ and ‘NSMutableArray’ classes as well as the buttonPressed: method
  • Import the ‘Image.h’ class and make the following changes.

[sourcecode]#import &lt;UIKit/UIKit.h&gt;
#import "Image.h"
@interface ImageGridViewController:UIViewController &lt;UITableViewDelegate, UITableViewDataSource&gt; {
IBOutlet UITableView *tableView;
NSMutableArray&nbsp; *sections;
}
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *sections;
-(IBAction)buttonPressed:(id)sender;
@end[/sourcecode]

Step 6:

  • Double click the ‘ImageGridViewController.xib’ file and open it in the Interface Builder.
  • First drag the ‘TableView’ from the library and place it in the view window.
  • Select ‘tableview’ from the view window and bring up connection inspector and connect ‘dataSource’ to the ‘File’s Owner’ and delegate to the ‘File’s Owner’ icon.
  • Now save the .xib file and go back to Xcode.

Step 7:

In the ‘ImageGridViewController.m’ file, make the following changes:

[sourcecode]#import "ImageGridViewController.h"
#import "Item.h" @implementation ImageGridViewController
@synthesize tableView,sections;

-(void)loadView{

[super loadView];
sections = [[NSMutableArray alloc] init];

for(int s=0;s&lt;1;s++) { // 4 sections
NSMutableArray *section = [[NSMutableArray alloc] init];

for(int i=0;i&lt;12;i++) {// 12 items in each section
Image *item = [[ Image alloc] init];
item.link=@"New Screen";
item.title=[NSString stringWithFormat:@"Item %d", i];
item.image=@"icon2.png";

[section addObject:item];
}
[sections addObject:section];
}
}

– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [sections count];
}

– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}

– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
NSMutableArray *sectionItems = [sections objectAtIndex:indexPath.section];
int numRows = [sectionItems count]/4;
return numRows * 80.0;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

NSString *sectionTitle = [NSString stringWithFormat:@"Section&nbsp; %d", section];
return sectionTitle;
}

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static&nbsp;&nbsp; &nbsp;NSString *hlCellID = @"hlCellID";

UITableViewCell *hlcell = [tableView dequeueReusableCellWithIdentifier:hlCellID];
if(hlcell == nil) {
hlcell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:hlCellID] autorelease];
hlcell.accessoryType = UITableViewCellAccessoryNone;
hlcell.selectionStyle = UITableViewCellSelectionStyleNone;
}

int section = indexPath.section;
NSMutableArray *sectionItems = [sections objectAtIndex:section];

int n = [sectionItems count];
int i=0,i1=0;

while(i&lt;n){
int yy = 4 +i1*74;
int j=0;
for(j=0; j&lt;4;j++){

if (i&gt;=n) break;
Image *item = [sectionItems objectAtIndex:i];
CGRect rect&nbsp; = CGRectMake(18+80*j, yy, 40, 40);
UIButton *buttonImage=[[UIButton alloc] initWithFrame:rect];
[buttonImage setFrame:rect];
UIImage *buttonImageNormal=[UIImage imageNamed:item.image];
[buttonImage setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
[buttonImage setContentMode:UIViewContentModeCenter];
NSString *tagValue = [NSString stringWithFormat:@"%d%d", indexPath.section+1, i];
buttonImage.tag = [tagValue intValue];
//NSLog(@tag….%d", button.tag);
[buttonImage addTarget:self
action:@selector(buttonPressed:)forControlEvents:UIControlEventTouchUpInside];
hlcell.contentView addSubview:buttonImage];
[buttonImage release];

UILabel *label = [[[UILabel alloc]initWithFrame:CGRectMake((80*j)-4, &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;yy+44, 80, 12)] autorelease];
label.text = item.title;
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.font = [UIFont fontWithName:@"ArialMT" size:12];
[hlcell.contentView addSubview:label];
i++;
}
i1 = i1+1;
}
return hlcell;
}
-(IBAction)buttonPressed:(id)sender {
int tagId = [sender tag];
int divNum = 0;
if(tagId&lt;100)
divNum=10;
else
divNum=100;
int section = [sender tag]/divNum;
section -=1;// we had incremented at tag assigning time
int itemId = [sender tag]%divNum;
NSLog(@"…section = %d, item = %d", section, itemId);
NSMutableArray*sectionItems = [sections objectAtIndex:section];
Image&nbsp;&nbsp; &nbsp;*item&nbsp;&nbsp; &nbsp;=&nbsp;&nbsp; &nbsp;[sectionItems objectAtIndex:itemId];
NSLog(@"Image selected…..%@, %@", item.title, item.link);

}

-(void)viewDidLoad{
[super viewDidLoad];
}

-(void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
}

-(void)viewDidUnload{
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

-(void)dealloc{
[super dealloc];
}
@end[/sourcecode]

Step 8:

Open the ‘Image.h’ file and make the following changes:

[sourcecode]#import &lt;Foundation/Foundation.h&gt;
@interface Image:NSObject{
NSString*title;
NSString*link;
NSString*image;
}
@property(nonatomic, copy)NSString*title;
@property(nonatomic, copy)NSString*link;
@property(nonatomic, copy)NSString*image;
@end[/sourcecode]

Step 9:

Make the changes in the ‘Item.m’ file:

[sourcecode]#import "Image.h"
@implementation Item
@synthesize title, link, image;
@end[/sourcecode]

Step 10:

Now save it and compile it in the Simulator.

It would be smart to use Grid View to display a number of images in a single view because it enables to manage multiple images efficiently. Users are also facilitated to keep track of their images. It becomes eye soothing and looks great on the iPhone mobile devices.

Keep visiting regularly to Andolasoft blog to know our upcoming article about the process to show your android Smartphone captured images dynamically in “Grid View” Layout.

IPhone 5S And IPad 5 Is Expected To Launch On 29th Of June

Apple’s next big thing is expected to lunch iphone 5s and ipad 5 on 29th of June of this year. Apparently iPhone 5S Smartphone will be entering the consumer market much earlier than what was expected. It is designed as a high-end sibling of the present generation iPhone 5. DigiTimes has revealed that the IPhone 5S will feature a faster processor, based on Apple’s ARM processing cores. They have also claimed that, it will have a higher-resolution camera than its previous models. These features can be disappointing for most users who find the phone’s design to be little boring and outdated compared to other major smart device manufacturers. But the next-generation iPhone 6 is expected to bring a fresh, updated and completely re-designed phone. Rumors have it that its design is inspired form iPad mini tablet.

Never miss an update from us. Join 10,000+ marketers and leaders.

DigiTimes’ sources has also pointed out that deliveries of essential iPhone 5S components are already scheduled to May, which makes sense that the launch date might be true. Resources have also stated that Apple is planning to launch iPad5 along with the iPhone 5S in an event on 29thof June. While unconfirmed from Apple, this date fits well with the earlier humors of the launch, but the inclusion of iPad 5 comes as something of a surprise. And these devices might be running iOS 7.

DigiTimes has released in their website stating-“Components for the next-generation iPhone will start shipping at the end of May with the new smartphone to have a chance of showing up in the third quarter, according to sources from the upstream supply chain.”

The new iPhone will not receive a major upgrade and may just be a slightly enhanced version of iPhone 5 (iPhone 5S), the sources said citing their latest specification data.”

If the event does really take place in June, It will be something of a test to iPhone 5S and iPad-5. This could also be the deciding factor of the company’s future. It will be the first major release from the company since the death of its co-founder Steve Jobs.

Major iphone application development company are also looking forward to the release of the new iPhone as well as the iOS 7. It will facilitate them to develop apps for the new OS with numerous new features and functionalities.

IPhone 5S And IPhone Mini Is Expected To Release This Year

According to some latest reports from an Apple Insider, it is claimed that, currently they are working on new iPhone models, which will be unveiled later this year. It is expected that there will be two iPhone models. One of these will be the next generation iPhone, presumably iPhone 5S and the other a cheaper iPhone with a polycarbonate body.

The next iPhone is expected by 2014 whereas the cheaper iPhone model can be expected to be released sooner this year.

Never miss an update from us. Join 10,000+ marketers and leaders.

MacRumours has also reported that according to Barclay’s analyst Kirk Yang, Apple is undeniably working on iPhone 5S and a cheaper iPhone, and about to launch in the August-September of this year.

Yang assumes that both the iPhones will have two models, one being made especially for Chinese customers. MacRumours further stated that, “The report claims that Apple is still weighing production volume for the new phones, working to estimate how much the lower-cost iPhone will cut into iPhone 5S sales and still gauging appropriate volumes for an expansion to China Mobile. Regardless, Apple does expect total iPhone shipments to be higher than last year’s levels.”

KGI Securities analyst Ming-Chi Kuo point out that the next generation iPhone will be called iPhone 5S, which will be identical to the iPhone 5. It will feature a faster 28 nanometer A7 chip, fingerprint sensor, smart LED flash and enhanced camera functionalities with f2.0 aperture.

The phone is expected to be available in two colors, just like the current iPhones, which contradicts its earlier rumors that new iPhone models would ship with multiple colors like the new iPod touch.

Pointing to the budget friendly iPhone 5, he pointed that it would be priced between $350 and $450, with a comparatively thicker (8.2 mm) plastic casing. He also revealed that the production might begin during the third quarter of this year.

Analyst Brian White pointed that Apple will release a new iPhone model with varying screen sizes that will help the company to earn revenue for reach models. He mentioned that the smaller iPhone version is specifically manufactured to target Chinese market and to open up opportunities in India.

I’ve worked with the team at Andolasoft on multiple websites. They are professional, responsive, & easy to work with. I’ve had great experiences & would recommend their services to anyone.

Ruthie Miller, Sr. Mktg. Specialist

Salesforce, Houston, Texas

LEARN MORE

Peter Misek’s findings mentioned that the next iPhone will feature a new super HD camera and display, longer battery power, NFC connectivity, IGZO screen for Retina+, 128GB storage, and could be available in multiple colors. He stated that many iPhone 5S prototypes were being tested in the recent past.

According to him the device had Retina+ IGZO display, A7 quad-core processor and in-built gesture control. It will feature a new design with no home button. He also referred the iPhone mini will be offered at a price range of $200 to $250 and said that the project hasn’t been approved yet.

Larger display with sharp images would help the iphone application developer to build vibrant iPhone applications with high definition images and sharp looking UIs. It would also affect the app design strategy for developers and designers.