ios照片获取、拍照功能

news/2024/12/1 0:49:38/
//
//  HYBPhotoPickerManager.h
//  ehui
//
//  Created by 黄仪标 on 14/11/26.
//  Copyright (c) 2014年 黄仪标. All rights reserved.
//#import <Foundation/Foundation.h>/*!* @brief 照片获取或者拍照功能管理器* @author huangyibiao*/
@interface HYBPhotoPickerManager : NSObject + (HYBPhotoPickerManager *)shared;/*!* @brief 选择图片或者拍照完成选择使用拍照的图片后,会调用此block* @param image 选择的图片或者拍照后选择使用的图片*/
typedef void (^HYBPickerCompelitionBlock)(UIImage *image);
/*!* @brief 用户点击取消时的回调block*/
typedef void (^HYBPickerCancelBlock)();/*!* @brief 此方法为调起选择图片或者拍照的入口,当选择图片或者拍照后选择使用图片后,回调completion,*        当用户点击取消后,回调cancelBlock* @param inView UIActionSheet呈现到inView这个视图上* @param fromController 用于呈现UIImagePickerController的控制器* @param completion 当选择图片或者拍照后选择使用图片后,回调completion* @param cancelBlock 当用户点击取消后,回调cancelBlock*/
- (void)showActionSheetInView:(UIView *)inViewfromController:(UIViewController *)fromControllercompletion:(HYBPickerCompelitionBlock)completioncancelBlock:(HYBPickerCancelBlock)cancelBlock;@end


//
//  HYBPhotoPickerManager.m
//  ehui
//
//  Created by 黄仪标 on 14/11/26.
//  Copyright (c) 2014年 黄仪标. All rights reserved.
//#import "HYBPhotoPickerManager.h"
#import "UIImagePickerController+Photo.h"
#import "UIImage+DSResizeAndRound.h"@interface HYBPhotoPickerManager () <UIImagePickerControllerDelegate,
UINavigationControllerDelegate,
UIActionSheetDelegate>@property (nonatomic, weak)     UIViewController          *fromController;
@property (nonatomic, copy)     HYBPickerCompelitionBlock completion;
@property (nonatomic, copy)     HYBPickerCancelBlock      cancelBlock;@end@implementation HYBPhotoPickerManager+ (HYBPhotoPickerManager *)shared {static HYBPhotoPickerManager *sharedObject = nil;static dispatch_once_t onceToken;dispatch_once(&onceToken, ^{if (!sharedObject) {sharedObject = [[[self class] alloc] init];}});return sharedObject;
}- (void)showActionSheetInView:(UIView *)inViewfromController:(UIViewController *)fromControllercompletion:(HYBPickerCompelitionBlock)completioncancelBlock:(HYBPickerCancelBlock)cancelBlock {self.completion = [completion copy];self.cancelBlock = [cancelBlock copy];self.fromController = fromController;dispatch_async(kGlobalThread, ^{UIActionSheet *actionSheet = nil;if ([UIImagePickerController isCameraAvailable]) {actionSheet  = [[UIActionSheet alloc] initWithTitle:nildelegate:(id<UIActionSheetDelegate>)selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"从相册选择", @"拍照上传", nil];} else {actionSheet = [[UIActionSheet alloc] initWithTitle:nildelegate:(id<UIActionSheetDelegate>)selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"从相册选择", nil];}dispatch_async(kMainThread, ^{[actionSheet showInView:inView];});});return;
}#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {if (buttonIndex == 0) { // 从相册选择if ([UIImagePickerController isPhotoLibraryAvailable]) {UIImagePickerController *picker = [[UIImagePickerController alloc] init];picker.delegate = self;picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;picker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType];if (kIsIOS7OrLater) {picker.navigationBar.barTintColor = self.fromController.navigationController.navigationBar.barTintColor;}// 设置导航默认标题的颜色及字体大小picker.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:18]};[self.fromController presentViewController:picker animated:YES completion:nil];}} else if (buttonIndex == 1) { // 拍照if ([UIImagePickerController canTakePhoto]) {UIImagePickerController *picker = [[UIImagePickerController alloc] init];picker.delegate = self;picker.sourceType = UIImagePickerControllerSourceTypeCamera;picker.delegate = self;if (kIsIOS7OrLater) {picker.navigationBar.barTintColor = self.fromController.navigationController.navigationBar.barTintColor;}// 设置导航默认标题的颜色及字体大小picker.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:18]};[self.fromController presentViewController:picker animated:YES completion:nil];}}return;
}#pragma mark - UIImagePickerControllerDelegate
// 选择了图片或者拍照了
- (void)imagePickerController:(UIImagePickerController *)aPicker didFinishPickingMediaWithInfo:(NSDictionary *)info {[aPicker dismissViewControllerAnimated:YES completion:nil];__block UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];if (image && self.completion) {[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];[self.fromController setNeedsStatusBarAppearanceUpdate];dispatch_async(kGlobalThread, ^{image = [image imageResizedToSize:CGSizeMake(kScreenWidth / 2.0, kScreenHeight / 2.0)];DDLogVerbose(@"image size : %@", NSStringFromCGSize(image.size));dispatch_async(kMainThread, ^{self.completion(image);});});}return;
}// 取消
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)aPicker {[aPicker dismissViewControllerAnimated:YES completion:nil];if (self.cancelBlock) {[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];[self.fromController setNeedsStatusBarAppearanceUpdate];self.cancelBlock();}return;
}@end



http://www.ppmy.cn/news/440912.html

相关文章

VFC芯片结构及其工作原理

&#xff08;二&#xff09; VFC芯片结构及其工作原理 1&#xff0e;VFC芯片 AD654的结构 AD654芯片是一个单片VFC变换芯片&#xff0c;中心频率为250kHZ。它是由阻抗变换器A、压控振荡器和一个驱动输出级回路构成&#xff0c;其内部结构见图1&#xff0d;15&#xff08;a入压…

iPhone 11 Pro 的拍照好在哪?这是专业摄影师给出的答案

来源 | AppSo&#xff08;ID&#xff1a;AppSo&#xff09; 作者 | 肖钦鹏 相机&#xff0c;无疑是新一代 iPhone 的最大卖点&#xff0c;在之前的 iPhone 11 和 iPhone 11 Pro 评测中&#xff0c;我曾这样评价&#xff1a; 我们以前常说&#xff0c;iPhone 是用做电脑的思路做…

iPhone语音拍照怎么用?

要如何实现iPhone声控拍照&#xff08;iOS语音拍照&#xff09;&#xff1f;在出去游玩时&#xff0c;想要一张美美的照片还要找人帮忙&#xff0c;其实iPhone语音拍照完全可以解决你的烦恼。iOS隐藏技巧&#xff0c;轻松实现iPhone声控拍照功能和Apple Watch无线控制iPhone相机…

ios 拍照与摄像

ios 拍照与摄像 (2012-11-23 14:38:40) 该类继承自UINavigationController类 步骤&#xff1a; 检查媒体来源模式是否可用 检查该来源模式下所支持的媒体类型 创建图像选取控制器&#xff0c;设置其属性并显示 在委托协议方法中处理 1.检查媒体来源 调用UIImagePickerControl…

iOS拍照图片方向

参考链接&#xff1a;1 iOS_UIImage的方向(imageOrientation) 2 iOS实时获取当前的屏幕方向之重力感应 3 UIImage图片处理&#xff0c;旋转、截取、平铺、缩放等操作&#xff0c;持续更新中 问题&#xff1a; 1.拍摄的图片直接推送到其他设备的显示&#xff0c;图片会有一定角度…

iphone和ipad拍照功能的实现

在iphone和ipad中&#xff0c;拍照的实现是不同的。 在iphone中&#xff1a; if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { picker [[UIImagePickerController alloc] init]; picker.delegate self; picker.sour…

iOS 拍照

UIImagePickerController拍照与摄像 (2012-11-23 14:38:40) 标签&#xff1a; ios iphone 拍照 摄像 杂谈 该类继承自UINavigationController类 步骤&#xff1a; 检查媒体来源模式是否可用 检查该来源模式下所支持的媒体类型 创建图像选取控制器&#xff0…

iPhone相机参数设置,苹果原相机也能拍出大片感

苹果原相机一直是大家拍照的首选&#xff0c;因为它的质感和清晰度绝对是手机相机里数一数二的。可有很多小伙伴自己或给女朋友拍照时&#xff0c;感觉拍出来像“照妖镜”&#xff0c;会丑化人像&#xff0c;特别是iPhone13用户普遍反映原相机拍照锐化十分严重。 如果你想成为…