相机的调用以及从相册中选取图片
来源:互联网 发布:kplayer mac 编辑:程序博客网 时间:2024/05/17 02:38
需要添加的代理
@interface ViewController :UIViewController<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
一、点击调取相机的按钮
- (void)chooseImage:(id)sender {
UIActionSheet *sheet;
//判断是否支持相机
if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
sheet = [[UIActionSheetalloc] initWithTitle:@"选择"delegate:selfcancelButtonTitle:nildestructiveButtonTitle:@"取消"otherButtonTitles:@"拍照",@"从相册选择",nil];
}
else {
sheet = [[UIActionSheetalloc] initWithTitle:@"选择"delegate:selfcancelButtonTitle:nildestructiveButtonTitle:@"取消"otherButtonTitles:@"从相册选择",nil];
}
sheet.tag =255;
[sheetshowInView:self.view];
}
二、底部弹出框事件
#pragma mark - actionsheet delegate
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (actionSheet.tag ==255) {
NSUInteger sourceType = 0;
// 判断是否支持相机
if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
switch (buttonIndex) {
case 0:
// 取消
return;
case 1:
// 相机
sourceType = UIImagePickerControllerSourceTypeCamera;
break;
case 2:
// 相册
sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
break;
}
}
else {
if (buttonIndex == 0) {
return;
}else {
sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
}
// 跳转到相机或相册页面
UIImagePickerController *imagePickerController = [[UIImagePickerControlleralloc] init];
imagePickerController.delegate =self;
imagePickerController.allowsEditing =YES;
imagePickerController.sourceType = sourceType;
[selfpresentViewController:imagePickerController animated:YES completion:^{}];
}
}
#pragma mark - image picker delegte
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YEScompletion:^{}];
UIImage *image = [infoobjectForKey:UIImagePickerControllerOriginalImage];
[selfsaveImage:imagewithName:@"currentImage.png"];
NSString *fullPath = [[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"currentImage.png"];
UIImage *savedImage = [[UIImagealloc] initWithContentsOfFile:fullPath];
isFullScreen =NO;
[self.imageViewsetImage:savedImage];
self.imageView.tag =100;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[selfdismissViewControllerAnimated:YEScompletion:^{}];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
isFullScreen = !isFullScreen;
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
CGPoint imagePoint = self.imageView.frame.origin;
//touchPoint.x ,touchPoint.y 就是触点的坐标
// 触点在imageView内,点击imageView时放大,再次点击时缩小
if(imagePoint.x <= touchPoint.x && imagePoint.x +self.imageView.frame.size.width >=touchPoint.x && imagePoint.y <= touchPoint.y && imagePoint.y+self.imageView.frame.size.height >= touchPoint.y)
{
// 设置图片放大动画
[UIViewbeginAnimations:nilcontext:nil];
// 动画时间
[UIViewsetAnimationDuration:1];
if (isFullScreen) {
// 放大尺寸
self.imageView.frame =CGRectMake(0,0, 320, 480);
}
else {
// 缩小尺寸
self.imageView.frame =CGRectMake(50,65, 90, 115);
}
// commit动画
[UIViewcommitAnimations];
}
}
#pragma mark - 保存图片至沙盒
- (void) saveImage:(UIImage *)currentImage withName:(NSString *)imageName
{
NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);
// 获取沙盒目录
NSString *fullPath = [[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:imageName];
// 将图片写入文件
[imageDatawriteToFile:fullPath atomically:NO];
}
- 相机的调用以及从相册中选取图片
- 从相册中选取图片
- Android调用系统相机以及拉取本地相册的功能实现以及代码分析
- 从相机拍摄和从相册读取图片,以及对图片的压缩的完全解决方案
- Intent拍照,从相册中选取
- Android开发从相册中选取照片
- iOS设备的摄像头进行拍照,视频。并且从相册中选取我们需要的图片或者视频。
- 调用手机摄像头拍照和从图库中选取照片以及得到照片后的备份
- 调用相机相册图片的方法
- 从手机中选取图片
- 打开相机拍照和从本地相册获取图片以及图片的剪切
- Android从相册中选取图片上传到阿里云OSS
- 调用系统相机拍照,从相册选取图片上传
- Android 调用相机或从相册获取图片
- android开发之上传图片和调用相机以及相册
- android中调用相机、相册 以及图片压缩,文件压缩
- 计算从ios照片库中选取的图片文件大小
- 从相册和相机选择图片以及图片压缩和android7.0相机
- Ios项目添加Pods
- GRE写作必备句型
- 发布与订阅信息
- 动态调用WebService的两种方法(多线程)
- 【数据运营】经验分享 :数据产品开发前的必修课|
- 相机的调用以及从相册中选取图片
- SqlServer索引的原理与应用
- php页面添加背景音乐 控制停止/播放
- segmentedControl设置字体和字体颜色问题
- 代码的坏味道
- 使用ViewPager实现循环滚动播放图片广告
- MyEclipse查找文件
- Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Fault occurred while processing.
- 虚拟内存的使用