Please disable AdBlock. CAN is an ad-supported site that takes hundreds of hours and thousands of dollars to sustain. Read More.
HOLO is a biannual magazine about emerging trajectories in art, science, and technology brought to you by the people behind CAN. Learn more!

Camera Apps [iPhone, Tutorial, openFrameworks]

This is an introduction tutorial in creating photo apps for the iPhone based on the tutorial by Atsushi Tadokoro. If you are already familiar with openFrameworks you can skip right to the “goal” section. If you haven’t used openframeworks before, read on to learn how to download, install and use xcode to get this tutorial on your iPhone.

Before we start, to be able to deploy development applications to the iPhone, ie run them on the device or publish to the AppStore, you will need to be registered with Apple as iPhone developer. This is a somewhat convoluted process but the registration itself does not take a lot of time. The downside that that it will cost you $99/year. You do not necessarily need to be registered as a iPhone developer to experiment with this tutorial as you can always use the iPhone emulator to play with your applications. Considering this is a photo application we are creating, you will not be able to take photos from the emulator, instead the code includes using images from the library when application is run in the emulator.

openFrameworks in an open source c++ creative code framework which runs inside xCode, a development application provided by Apple as a part of Apple SDK (software development kit). To be able to use oF (openFrameworks) you first need to download iPhone SDK (Download). You will need to register on Apple’s site to gain access to the download but this is pretty straight forward. Once you have download and installed xCode, you need to download openFrameworks. oF comes in a number of versions, the one you want is v0061_iPhone. This is the latest official release at the time of writing this tutorial. Should you want to jump ahead, you can always look at the github source, the latest development version. For this tutorial, v0061_iPhone should be good to go. Download oF and unzip the folder. You can put the oF folder anywhere on your computer, what is important is that all the applications you create (xCode Projects) are located inside this folder. The correct location for all your files should be openframeworksfolder/apps/yournameorappname/xcodeprojectsfolders. It’s really important that you have another folder between apps and your xcode projects. oF xCode projects include a bunch of references to the files contained within the oF folder. Regardless of whether you new app is empty or not, for it to compile (build/run), needs to know where the main oF files are.

To start a new project, duplicate “emptyExample” folder located inside /apps/iPhoneExamples folder and put it in the appropriate new folder inside /apps folder (see above). This is your starting file and should contain all the link and references to get going.

NOTE: The making of this original tutorial happened before the latest version of Apple SDK (the one you just downloaded) was available. To make your tutorial files run, you will need to change BASE SDK configuration. To do this, inside xcode, go to the left menu, expand “targets” folder and double click on the application. Change “Base SDK” to “iOS Device 4.1″. Alternatively, download the working (oFv0061_iPhone) emptyExample here. If you are downloading files below, you will need to do the same to them.

When you open the example project, you will find many folders on the left and link to other files. You should be concerned (for the time being) only with the files located inside the “src” folder, the the source folder. There you will find main.mmtestApp.h and testApp.mm files. main.mm file you will hardly ever need to touch, this just defines global settings, testApp.h is where your definitions go, ie for example the variables and testApp.mm is where your code sits. In the following examples will be dealing with testApp.h and testApp.mm files.

To test whether your example project works, click on the “Build and Run” button in the top of the xCode window. To ensure you are deploying to the emulator and not device, make sure that on the left pull down menu “simulator” is selected. Alternatively if you would like to deploy straight to your device, choose “device”. If you code is good, you should now see emulator open running your empty application or do the same on the device.

The basic setup of oF files is very similar to Processing if you used it before. If not, basically there are a number of events that take place when your iphone goes through your code. First one is setup, this is where you predefine all the things that run only once. Update is where things happen each frame, say for example you want the object to move from left to right, well you’d do that in the update, telling in the code to move the object by 1 pixel with each progressing frame. Draw is where you say what to draw on the screen. touchDown is what happens when you tap on the screen, touchMoved when you move your finger along the screen, touchup is when your release and the one we are going to be using here is touchDoubleTap, what happens when you tap twice on the screen. For the sake of keeping this example simple, we’ll just use double tap as a button to open camera.

Now we are ready to jump into the code.

Take a Picture

We are going to first learn how to take a simple picture. Once we know that, we’ll learn how to apply effects or alter pixel data we obtain from the camera.

- Built-in camera to take pictures, images of photographs (ofImage) to copy and display
- The underlying features of the camera application and later

Your testApp.h

[sourcecode language="c"]
#pragma once

#include "ofMain.h"
#include "ofxiPhone.h"
#include "ofxiPhoneExtras.h"

class testApp : public ofxiPhoneApp {

public:
void setup();
void update();
void draw();
void exit();

void touchDown(ofTouchEventArgs &touch);
void touchMoved(ofTouchEventArgs &touch);
void touchUp(ofTouchEventArgs &touch);
void touchDoubleTap(ofTouchEventArgs &touch);

void lostFocus();
void gotFocus();
void gotMemoryWarning();
void deviceOrientationChanged(int newOrientation);

unsigned char * cameraPixels;
ofxiPhoneImagePicker * camera;
ofImage photo;
int status;

};
[/sourcecode]

Your testApp.mm

[sourcecode language="c"]
#include "testApp.h"

//————————————————————–
void testApp::setup(){
// register touch events
ofRegisterTouchEvents(this);

// initialize the accelerometer
ofxAccelerometer.setup();

//iPhoneAlerts will be sent to this.
ofxiPhoneAlerts.addListener(this);

//If you want a landscape oreintation
//iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);

ofBackground(127,127,127);

cameraPixels = NULL;
camera = new ofxiPhoneImagePicker();
camera->setMaxDimension(480);

status = 0;
}

//————————————————————–
void testApp::update(){

#ifndef _USE_SIMULATOR
//condition to use simulator for testing
if(camera->imageUpdated){
//Camera’s memory space
if (cameraPixels == NULL){
cameraPixels = new unsigned char [camera->width * camera->height*4];
}

//Now that I’m still upside down camera images, the image upside down
for (int i = 0; i < camera->height; i++){
memcpy(cameraPixels+(camera->height-i-1)*camera->width*4, camera->pixels+i*camera->width*4, camera->width*4);
}

// The captured image from the camera for processing ofImage (photo) Copy
photo.setFromPixels(cameraPixels, camera->width, camera->height, OF_IMAGE_COLOR_ALPHA);
camera->imageUpdated = false;
status = 1;
}
#endif

}

//————————————————————–
void testApp::draw(){

if (status == 0) {
//Display the screen to shoot
ofSetColor(255, 255, 255);
ofDrawBitmapString("Double tap on the screen!!", 40, ofGetHeight()/2-5);
}

if(status == 1){
//Display the captured image
photo.draw(0, 0);
}

}

//————————————————————–
void testApp::exit(){

}

//————————————————————–
void testApp::touchDown(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchMoved(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchUp(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchDoubleTap(ofTouchEventArgs &touch){

////UNCOMMENT/COMMENT AS NEEDED

////If using Simulator: loading images

// photo.loadImage("images/photo.png");
// photo.setImageType(OF_IMAGE_COLOR_ALPHA);
// status = 1;

////or to open Photo library in the simulator or actual device

//camera->openLibrary();

//When using real: a new photo shoot

camera->openCamera();

}

//————————————————————–
void testApp::lostFocus(){

}

//————————————————————–
void testApp::gotFocus(){

}

//————————————————————–
void testApp::gotMemoryWarning(){

}

//————————————————————–
void testApp::deviceOrientationChanged(int newOrientation){

}
[/sourcecode]

Camera Mosaic

- Processed into a mosaic of photographs
- Picked up at regular intervals of pixel information photographs, drawing a rectangle RGB obtained based on information
- Pixel information of the photographic image, getPixel () function is used to remove
- Photographic image, every pixel 1 RGBA (Red, Green, Blue, Alpha) that contains information on four
- When we scan the pixel is treated as one unit to keep in mind four pixels

Your testApp.h

[sourcecode language="c"]
#pragma once

#include "ofMain.h"
#include "ofxiPhone.h"
#include "ofxiPhoneExtras.h"

class testApp : public ofxiPhoneApp {

public:
void setup();
void update();
void draw();
void exit();

void touchDown(ofTouchEventArgs &touch);
void touchMoved(ofTouchEventArgs &touch);
void touchUp(ofTouchEventArgs &touch);
void touchDoubleTap(ofTouchEventArgs &touch);

void lostFocus();
void gotFocus();
void gotMemoryWarning();
void deviceOrientationChanged(int newOrientation);

unsigned char * cameraPixels;
ofxiPhoneImagePicker * camera;
ofImage photo;
int status;

};
[/sourcecode]

Your testApp.mm

[sourcecode language="c"]

#include "testApp.h"

//————————————————————–
void testApp::setup(){
// register touch events
ofRegisterTouchEvents(this);

// initialize the accelerometer
ofxAccelerometer.setup();

//iPhoneAlerts will be sent to this.
ofxiPhoneAlerts.addListener(this);

//If you want a landscape oreintation
//iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);

ofBackground(127,127,127);

cameraPixels = NULL;
camera = new ofxiPhoneImagePicker();
camera->setMaxDimension(480);

status = 0;
}

//————————————————————–
void testApp::update(){

#ifndef _USE_SIMULATOR
//When using real
if(camera->imageUpdated){
//Camera’s memory space
if (cameraPixels == NULL){
cameraPixels = new unsigned char [camera->width * camera->height*4];
}

// Now that I’m still upside down camera images, the image upside down
for (int i = 0; i < camera->height; i++){
memcpy(cameraPixels+(camera->height-i-1)*camera->width*4, camera->pixels+i*camera->width*4, camera->width*4);
}

// The captured image from the camera for processing ofImage (photo) Copy
photo.setFromPixels(cameraPixels, camera->width, camera->height, OF_IMAGE_COLOR_ALPHA);
camera->imageUpdated = false;
status = 1;
}
#endif

}

//————————————————————–
void testApp::draw(){

if (status == 0) {
//Display the screen to shoot
ofSetColor(255, 255, 255);
ofDrawBitmapString("Double tap on the screen!!", 40, ofGetHeight()/2-5);
}

if(status == 1){
//Display the captured image
photo.draw(0, 0);

//Bitmap information stored in the array of image data
unsigned char * pixels = photo.getPixels();

//Image width and height of income
int w = photo.width;
int h = photo.height;

//スキャンする間隔
int skip = 20;

//Of a mosaic: the pixel color at regular intervals to detect and draw
for (int j = 0; j < h; j+=skip){
for (int i = 0; i < w; i+=skip){
int valueR = pixels[j*4*w + i*4];
int valueG = pixels[j*4*w + i*4+1];
int valueB = pixels[j*4*w + i*4+2];
ofSetColor(valueR,valueG,valueB);
ofRect(i, j, skip, skip);
}
}
}
}

//————————————————————–
void testApp::exit(){

}

//————————————————————–
void testApp::touchDown(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchMoved(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchUp(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchDoubleTap(ofTouchEventArgs &touch){

////UNCOMMENT/COMMENT AS NEEDED

////If using Simulator: loading images

// photo.loadImage("images/photo.png");
// photo.setImageType(OF_IMAGE_COLOR_ALPHA);
// status = 1;

////or to open Photo library in the simulator or actual device

//camera->openLibrary();

//When using real: a new photo shoot

camera->openCamera();

}

//————————————————————–
void testApp::lostFocus(){

}

//————————————————————–
void testApp::gotFocus(){

}

//————————————————————–
void testApp::gotMemoryWarning(){

}

//————————————————————–
void testApp::deviceOrientationChanged(int newOrientation){

}
[/sourcecode]

Scan Camera

- Using the application of Mosaic
- A certain height (Y coordinate) of the pixel information
- All X coordinate to obtain RGBA values, like displaying a vertical bar to expand
- To get height, which can be changed by touching the screen
- Effects can be obtained at the specified line to scan photos

Your testApp.h

[sourcecode language="c"]

#pragma once

#include "ofMain.h"
#include "ofxiPhone.h"
#include "ofxiPhoneExtras.h"

class testApp : public ofxiPhoneApp {

public:
void setup();
void update();
void draw();
void exit();

void touchDown(ofTouchEventArgs &touch);
void touchMoved(ofTouchEventArgs &touch);
void touchUp(ofTouchEventArgs &touch);
void touchDoubleTap(ofTouchEventArgs &touch);

void lostFocus();
void gotFocus();
void gotMemoryWarning();
void deviceOrientationChanged(int newOrientation);

unsigned char * cameraPixels;
ofxiPhoneImagePicker * camera;
ofImage photo;
int status;
int scanHeight;
};
[/sourcecode]

Your testApp.mm

[sourcecode language="c"]
#include "testApp.h"

//————————————————————–
void testApp::setup(){
// register touch events
ofRegisterTouchEvents(this);

// initialize the accelerometer
ofxAccelerometer.setup();

//iPhoneAlerts will be sent to this.
ofxiPhoneAlerts.addListener(this);

//If you want a landscape oreintation
//iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);

ofBackground(127,127,127);

cameraPixels = NULL;
camera = new ofxiPhoneImagePicker();
camera->setMaxDimension(480);

status = 0;
}

//————————————————————–
void testApp::update(){

#ifndef _USE_SIMULATOR
//When using real
if(camera->imageUpdated){
//Camera’s memory space
if (cameraPixels == NULL){
cameraPixels = new unsigned char [camera->width * camera->height*4];
}

// Now that I’m still upside down camera images, the image upside down
for (int i = 0; i < camera->height; i++){
memcpy(cameraPixels+(camera->height-i-1)*camera->width*4, camera->pixels+i*camera->width*4, camera->width*4);
}

// The captured image from the camera for processing ofImage (photo) Copy
photo.setFromPixels(cameraPixels, camera->width, camera->height, OF_IMAGE_COLOR_ALPHA);
camera->imageUpdated = false;
status = 1;
}
#endif

}

//————————————————————–
void testApp::draw(){

if (status == 0) {
//Display the screen to shoot
ofSetColor(255, 255, 255);
ofDrawBitmapString("Double tap on the screen!!", 40, ofGetHeight()/2-5);
}

if(status == 1){
//Display the captured image
photo.draw(0, 0);

//Bitmap information stored in the array of image data
unsigned char * pixels = photo.getPixels();

//Image width and height of income
int w = photo.width;
int h = photo.height;

//Of a mosaic: the pixel color at regular intervals to detect and draw
for (int i = 0; i < w; i++){
int valueR = pixels[scanHeight*4*w + i*4];
int valueG = pixels[scanHeight*4*w + i*4+1];
int valueB = pixels[scanHeight*4*w + i*4+2];
ofSetColor(valueR,valueG,valueB);
ofRect(i, 0, 1, h);
}

//Display it where to scan
ofSetColor(255, 255, 255);
ofLine(0, scanHeight, ofGetWidth(), scanHeight);
}
}

//————————————————————–
void testApp::exit(){

}

//————————————————————–
void testApp::touchDown(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchMoved(ofTouchEventArgs &touch){
//Where you drag the screen to determine the height scan
scanHeight = touch.y;

}

//————————————————————–
void testApp::touchUp(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchDoubleTap(ofTouchEventArgs &touch){

////UNCOMMENT/COMMENT AS NEEDED

////If using Simulator: loading images

// photo.loadImage("images/photo.png");
// photo.setImageType(OF_IMAGE_COLOR_ALPHA);
// status = 1;

////or to open Photo library in the simulator or actual device

//camera->openLibrary();

//When using real: a new photo shoot

camera->openCamera();

}

//————————————————————–
void testApp::lostFocus(){

}

//————————————————————–
void testApp::gotFocus(){

}

//————————————————————–
void testApp::gotMemoryWarning(){

}

//————————————————————–
void testApp::deviceOrientationChanged(int newOrientation){

}
[/sourcecode]

Pixelate Camera (Greyscale)

- Analysis of photographic images pixel information
- RGB images at a constant interval to another level (brightness) to get, taking the average value
- Going in circles while changing the radius value
- As gray dots represent the photo that was printed in black and white

Your testApp.h

[sourcecode language="c"]
#pragma once

#include "ofMain.h"
#include "ofxiPhone.h"
#include "ofxiPhoneExtras.h"

class testApp : public ofxiPhoneApp {

public:
void setup();
void update();
void draw();
void exit();

void touchDown(ofTouchEventArgs &touch);
void touchMoved(ofTouchEventArgs &touch);
void touchUp(ofTouchEventArgs &touch);
void touchDoubleTap(ofTouchEventArgs &touch);

void lostFocus();
void gotFocus();
void gotMemoryWarning();
void deviceOrientationChanged(int newOrientation);

unsigned char * cameraPixels;
ofxiPhoneImagePicker * camera;
ofImage photo;
int status;

};
[/sourcecode]

Your testApp.mm

[sourcecode language="c"]
#include "testApp.h"

//————————————————————–
void testApp::setup(){
// register touch events
ofRegisterTouchEvents(this);

// initialize the accelerometer
ofxAccelerometer.setup();

//iPhoneAlerts will be sent to this.
ofxiPhoneAlerts.addListener(this);

//If you want a landscape oreintation
//iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);

ofBackground(127,127,127);
ofEnableSmoothing();
ofSetCircleResolution(64);
ofEnableAlphaBlending();

cameraPixels = NULL;
camera = new ofxiPhoneImagePicker();
camera->setMaxDimension(480);

status = 0;
}

//————————————————————–
void testApp::update(){

#ifndef _USE_SIMULATOR
//When using real
if(camera->imageUpdated){
//Camera’s memory space
if (cameraPixels == NULL){
cameraPixels = new unsigned char [camera->width * camera->height*4];
}

// Now that I’m still upside down camera images, the image upside down
for (int i = 0; i < camera->height; i++){
memcpy(cameraPixels+(camera->height-i-1)*camera->width*4, camera->pixels+i*camera->width*4, camera->width*4);
}

// The captured image from the camera for processing ofImage (photo) Copy
photo.setFromPixels(cameraPixels, camera->width, camera->height, OF_IMAGE_COLOR_ALPHA);
camera->imageUpdated = false;
status = 1;
}
#endif

}

//————————————————————–
void testApp::draw(){

if (status == 0) {
//Display the screen to shoot
ofSetColor(255, 255, 255);
ofDrawBitmapString("Double tap on the screen!!", 40, ofGetHeight()/2-5);
}

if(status == 1){
//Display the captured image
photo.draw(0, 0);

//Bitmap information stored in the array of image data
unsigned char * pixels = photo.getPixels();

//Image width and height of income
int w = photo.width;
int h = photo.height;

//Set the radius of the pixelate
int r = 12;

//Scan the image at regular intervals
for (int j = 0; j < h; j+=r){
for (int i = 0; i < w; i+=r){
//Get the value of RGB pixel
//RGBA so arranged in the order of 4 per pixel
int valueR = pixels[j*4*w + i*4];
int valueG = pixels[j*4*w + i*4+1];
int valueB = pixels[j*4*w + i*4+2];

//RGB values for calculating the average value of
float value = r*(valueR+valueG+valueB)/2.0/255.0;

//Get the RGB values based on drawing a circle
//Get the brightness of the pixels, which will correspond to the radius
ofSetColor(255,255,255,100);
ofCircle(i, j, value);
}
}

}
}

//————————————————————–
void testApp::exit(){

}

//————————————————————–
void testApp::touchDown(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchMoved(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchUp(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchDoubleTap(ofTouchEventArgs &touch){

////UNCOMMENT/COMMENT AS NEEDED

////If using Simulator: loading images

// photo.loadImage("images/photo.png");
// photo.setImageType(OF_IMAGE_COLOR_ALPHA);
// status = 1;

////or to open Photo library in the simulator or actual device

//camera->openLibrary();

//When using real: a new photo shoot

camera->openCamera();

}

//————————————————————–
void testApp::lostFocus(){

}

//————————————————————–
void testApp::gotFocus(){

}

//————————————————————–
void testApp::gotMemoryWarning(){

}

//————————————————————–
void testApp::deviceOrientationChanged(int newOrientation){

}
[/sourcecode]

Pixelate Camera (Colour)

- The color version of Pixelate
- RGB separate circles, we repeatedly
- The synthesis of color when drawing the point where the change is additive synthesis
- Use OpenGL commands directly – glEnable (GL_BLEND); and glBlendFunc (GL_SRC_ALPHA, GL_ONE); feasible
- As gray dots represent a color photograph printed as

Your testApp.h

[sourcecode language="c"]
#pragma once

#include "ofMain.h"
#include "ofxiPhone.h"
#include "ofxiPhoneExtras.h"

class testApp : public ofxiPhoneApp {

public:
void setup();
void update();
void draw();
void exit();

void touchDown(ofTouchEventArgs &touch);
void touchMoved(ofTouchEventArgs &touch);
void touchUp(ofTouchEventArgs &touch);
void touchDoubleTap(ofTouchEventArgs &touch);

void lostFocus();
void gotFocus();
void gotMemoryWarning();
void deviceOrientationChanged(int newOrientation);

unsigned char * cameraPixels;
ofxiPhoneImagePicker * camera;
ofImage photo;
int status;

};
[/sourcecode]

Your testApp.mm

[sourcecode language="c"]
#include "testApp.h"

//————————————————————–
void testApp::setup(){
// register touch events
ofRegisterTouchEvents(this);

// initialize the accelerometer
ofxAccelerometer.setup();

//iPhoneAlerts will be sent to this.
ofxiPhoneAlerts.addListener(this);

//If you want a landscape oreintation
//iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);

ofBackground(127,127,127);
ofEnableSmoothing();
ofSetCircleResolution(64);
ofEnableAlphaBlending();

cameraPixels = NULL;
camera = new ofxiPhoneImagePicker();
camera->setMaxDimension(480);

status = 0;
}

//————————————————————–
void testApp::update(){

#ifndef _USE_SIMULATOR
//When using real
if(camera->imageUpdated){
//Camera’s memory space
if (cameraPixels == NULL){
cameraPixels = new unsigned char [camera->width * camera->height*4];
}

// Now that I’m still upside down camera images, the image upside down
for (int i = 0; i < camera->height; i++){
memcpy(cameraPixels+(camera->height-i-1)*camera->width*4, camera->pixels+i*camera->width*4, camera->width*4);
}

// The captured image from the camera for processing ofImage (photo) Copy
photo.setFromPixels(cameraPixels, camera->width, camera->height, OF_IMAGE_COLOR_ALPHA);
camera->imageUpdated = false;
status = 1;
}
#endif

}

//————————————————————–
void testApp::draw(){

if (status == 0) {
//Display the screen to shoot
ofSetColor(255, 255, 255);
ofDrawBitmapString("Double tap on the screen!!", 40, ofGetHeight()/2-5);
}

if(status == 1){
//Display the captured image
photo.draw(0, 0);

//Bitmap information stored in the array of image data
unsigned char * pixels = photo.getPixels();

//Image width and height of income
int w = photo.width;
int h = photo.height;

//Set the radius of the pixelate
int r = 12;

//Scan the image at regular intervals
for (int j = 0; j < h; j+=r){
for (int i = 0; i < w; i+=r){
//Get the value of RGB pixel
//RGBA so arranged in the order of 4 per pixel
int valueR = pixels[j*4*w + i*4];
int valueG = pixels[j*4*w + i*4+1];
int valueB = pixels[j*4*w + i*4+2];

// Get the RGB values based on drawing a circle
// Get the brightness of the pixels, which will correspond to the radius of the circle
ofSetColor(255, 0, 0, 63);
ofCircle(i, j, r*valueR/255.0*2.0);
ofSetColor(0, 255, 0, 63);
ofCircle(i, j, r*valueG/255.0*2.0);
ofSetColor(0, 0, 255, 63);
ofCircle(i, j, r*valueB/255.0*2.0);
}
}

}
}

//————————————————————–
void testApp::exit(){

}

//————————————————————–
void testApp::touchDown(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchMoved(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchUp(ofTouchEventArgs &touch){

}

//————————————————————–
void testApp::touchDoubleTap(ofTouchEventArgs &touch){

////UNCOMMENT/COMMENT AS NEEDED

////If using Simulator: loading images

// photo.loadImage("images/photo.png");
// photo.setImageType(OF_IMAGE_COLOR_ALPHA);
// status = 1;

////or to open Photo library in the simulator or actual device

//camera->openLibrary();

//When using real: a new photo shoot

camera->openCamera();

}

//————————————————————–
void testApp::lostFocus(){

}

//————————————————————–
void testApp::gotFocus(){

}

//————————————————————–
void testApp::gotMemoryWarning(){

}

//————————————————————–
void testApp::deviceOrientationChanged(int newOrientation){

}
[/sourcecode]

Conclusion

As you can see, you can produce quite a lot with very little code indeed. Of course, this is just the beginning and if you were interested in building a real app out of any of the above examples you would also build an UI, buttons, help, etc. The ‘draw’ method is your friend, from simple rectangles to make buttons to code in the touchdown such as:

if(touch.x>70 && touch.x<90 && touch.y>325 && touch.y<355) {

//somethings happens here

}

to define the click are where something might happen, such as opening the library of photos (camera-> openLibrary (); instead of camera-> openCamera ();)

To see the full reference of commands, see openFrameworks website.

We hope this has been useful and provided a nice + quick introduction into openFrameworks on the iPhone. Any other tutorials you would like to see or if you have any questions please leave a comment below.

DOWNLOAD TUTORIAL FILES

Credits

This tutorial first appeared on http://yoppa.org, created by Atsushi Tadokoro. Introduction and translation by Filip Visnjic with the help of google translate, together with few changes to make it easier for beginners (i hope).

    • http://www.facebook.com/kamend Kamen Dimitrov

      http://www.jeffcrouse.info/how-tos/ofxiphonevidgrabber-and-ofxopencviphone/ this is a very good addition to this tutorial and more likely to get accepted in the AppStore :)

    • http://www.creativeapplications.net Filip

      Kamen, ofxvideograbber is now part of openFrameworks, ie addon and if you want to experiment, working with the latest oF dev version might be better way to go..
      https://github.com/openframeworks/openFrameworks/tree/swappable/addons/ofxiPhone/src/

    • julienbayle

      trying to use it with sharekit to add a sharing feature to my app.

      before that, I’d have to save it into the iOS device gallery because sharekit seems to be able to share only saved (of course) pictures.

      any ideas?

    • arthur

      hi, i’m new to xcode, and i was wondering if you could help, i keep getting a problem, any help please?

      thanks

      #ifdef __OBJC__
      #import
      #import
      #endif

    • arthur

      and the error is that it cant find the foundation foundation.h. soz