//当选择的类型是图片
129
if ([type isEqualToString:@"public.image"])
130
{
131
//先把图片转成NSData
132
UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
133
NSData *data;
134
if (UIImagePNGRepresentation(image) == nil)
135
{
136
data = UIImageJPEGRepresentation(image, 1.0);
137
}
138
else
139
{
140
data = UIImagePNGRepresentation(image);
141
}
142
143
//图片保存的路径
144
//这里将图片放在沙盒的documents文件夹中
145
NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
146
147
//文件管理器
148
NSFileManager *fileManager = [NSFileManager defaultManager];
149
150
//把刚刚图片转换的data对象拷贝至沙盒中 并保存为image.png
151
[fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
152
[fileManager createFileAtPath:[DocumentsPath stringByAppendingString:@"/image.png"] contents:data attributes:nil];
153
154
//得到选择后沙盒中图片的完整路径
155
filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath, @"/image.png"];
156
157
//关闭相册界面
158
[picker dismissModalViewControllerAnimated:YES];
159
160
//创建一个选择后图片的小图标放在下方
161
//类似微薄选择图后的效果
162
UIImageView *smallimage = [[[UIImageView alloc] initWithFrame:
163
CGRectMake(50, 120, 40, 40)] autorelease];
164
165
smallimage.image = image;
166
//加在视图中
167
[self.view addSubview:smallimage];
168
169
}
170
171
}
172
173
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
174
{
175
NSLog(@"您取消了选择图片");
176
[picker dismissModalViewControllerAnimated:YES];
177
}
178
179
-(void)sendInfo
180
{
181
NSLog(@"图片的路径是:%@", filePath);
182
183
NSLog(@"您输入框中的内容是:%@", _textEditor.text);
184
}
185
186
- (void)viewDidUnload
187
{
188
[super viewDidUnload];
189
// Release any retained subviews of the main view.
190
}
191
192
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
193
{
194
return (interfaceOrientation == UIInterfaceOrientationPortrait);
195
}
196
197
@end