2013-03-24 59 views
0

我想對我在我的應用中捕獲的照片應用濾鏡效果。我需要3個按鈕來調用這些效果(例如,一個用於黑白,一個用於棕褐色,另一個用於Vintage)。所以這是我的問題。下面你會看到我的圖像保存時的代碼。你會在那裏看到「img = [img e1]」。這將圖像保存爲黑白圖像。如果我做了「img = [img e2]」,那將是棕褐色。如果我想讓這種效果永久化,我的代碼就可以正常工作。問題是我需要按鈕來改變不同的電子號碼,如果這是有道理的。對不起,如果這不是很好解釋。有一個按鈕應用效果xcode

- (void)captureEnded:(CameraView *)camView { 
NSLog(@"%f, %f", [camView capturedImage].size.width, [camView capturedImage].size.height) 

UIImage *img = [camView capturedImage]; 
img = [img e1]; 
    img = [UIImage imageWithCGImage:[ self rotateImage:img angle:90 ].CGImage 
          scale:1.0 orientation: UIImageOrientationUp]; 

UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil); 

回答

0

你可以聲明

UIImage *img; 
在頭.h文件中,並在你的主類

寫三個按鈕的動作

-(IBAction) nbutton1{ 

IMG = [IMG E1]

}

-(IBAction) nbutton2{ 

IMG = [IMG E2];

}

-(IBAction) nbutton3{ 

IMG = [IMG E3];

}

0

陣列方法名的

NSArray *methodArray = [NSArray arrayWithObjects:@"e1", @"e2", @"e3", nil]; 

聲明在陣列用於與名稱方法

- (void)e1 
{ 
    // Code for Black & White effect 
} 

- (void)e2 
{ 
    // Code for Sepia effect 
} 

- (void)e3 
{ 
    // Code for Vignet effect 
} 

現在調用方法與陣列的對象使用以下代碼

[self performSelector:NSSelectorFromString([methodArray objectAtIndex:0])]; // call to method e1 
[self performSelector:NSSelectorFromString([methodArray objectAtIndex:1])]; // call to method e2 
[self performSelector:NSSelectorFromString([methodArray objectAtIndex:2])]; // call to method e3