ImplementationUiactionsheetdelegate
Uiactionsheet * menu = [[uiactionsheet
Alloc]
Initwithtitle :@""
Delegate: Self
Cancelbuttontitle: @ "cancel"
Destructivebuttontitle: Nil
Otherbuttontitles: @ "image album", @ "photo ",
Nil];
[Menu
Showinview: Self. View];
# Pragma mark uiactionsheet Method
-(Void) actionsheet :( uiactionsheet *) actionsheet clickedbuttonatindex :( nsinteger) buttonindex
{
If (buttonindex = 0 ){
[Self
Photoalbumr]; // image album
} Else
If (buttonindex = 1 ){
[Self
Photocamera]; // take a photo
} Else
If (buttonindex = 2 ){
}
[Actionsheet
Release];
}
Call the system album
ImplementationUiimagepickercontrollerdelegate
-(Void) photoalbumr {
If ([uiimagepickercontroller
Issourcetypeavailable:
Uiimagepickercontrollersourcetypephotolibrary]) {
Uiimagepickercontroller * picker =
[[Uiimagepickercontroller
Alloc]
Init];
Picker. Delegate =
Self;
Picker. allowsimageediting =
Yes;
Picker. sourcetype =
Uiimagepickercontrollersourcetypephotolibrary;
[Self
Presentmodalviewcontroller: picker animated: Yes];
[Picker
Release];
}
Else {
Uialertview * Alert = [uialertview
Alloc]
Initwithtitle: @ "Error accessing photo library"
Message: @ "device does not support a photo library"
Delegate: Nil
Cancelbuttontitle: @ "Drat! "
Otherbuttontitles: Nil];
[Alert
Show];
[Alert
Release];
}
}
-(Void) photocamera {
If ([uiimagepickercontroller
Issourcetypeavailable: uiimagepickercontrollersourcetypecamera]) {
Uiimagepickercontroller * imagepicker = [uiimagepickercontroller
Alloc]
Init];
Imagepicker. Delegate =
Self;
Imagepicker. sourcetype =
Uiimagepickercontrollersourcetypecamera;
Imagepicker. modaltransitionstyle =
Uimodaltransitionstylecoververtical;
Imagepicker. allowsediting =
Yes;
[Self
Presentmodalviewcontroller: imagepicker
Animated: Yes];
}
Else {
Uialertview * Alert = [uialertview
Alloc]
Initwithtitle: @ "sorry"
Message: @ "the device does not support the photo taking function"
Delegate: Nil
Cancelbuttontitle: @ "OK"
Otherbuttontitles: Nil];
[Alert
Show];
[Alert
Release];
}
}
# Pragma mark uiimagepicker Method
-(Void) imagepickercontroller :( uiimagepickercontroller *) picker
Didfinishpickingimage :( uiimage *) Image
Editinginfo :( nsdictionary *) editinginfo
{
/*Store images under document
Nsarray * paths =
Nssearchpathfordirectoriesindomains (nsdocumentdirectory,
Nsuserdomainmask, yes );
Nsstring * documentsdirectory = [paths objectatindex: 0];
Nsstring * savedimagepath = [documentsdirectory
Stringbyappendingpathcomponent: @ "savedimage.png"];
Nsdata * imagedata = uiimagepngrepresentation (image );
[Imagedata
Writetofile: savedimagepath atomically: No];
_ Imgname = @ "savedimage.png ";
Self. _ imgfilepath = documentsdirectory;
*/
[Addphoto
Setbackgroundimage: Image forstate: uicontrolstatenormal];
[Picker
Dismissmodalviewcontrolleranimated: Yes];
}
// Select
-(Void) imagepickercontrollerdidcancel :( uiimagepickercontroller *) picker
{
[Picker
Dismissmodalviewcontrolleranimated: Yes];
}