我到了ios的相机课。 ADMSImageUploader.h如下
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <AssetsLibrary/AssetsLibrary.h>
@interface ADMSImageUploader : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property BOOL newMedia;
@property (weak, nonatomic) IBOutlet UIImageView *previewImage;
- (IBAction)returnButtonClicked:(id)sender;
- (IBAction)retakeButtonClicked:(id)sender;
- (IBAction)uploadButtonClicked:(id)sender;
-(void)openCamera:(NSString *)dealerId : (NSString *)inventoryId;
@end
.m文件中的代码如下。下面有一个功能打开相机
-(void)useCamera{
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
_newMedia = YES;
}
}
这是相机的图像
我想阻止下面的屏幕出现并将捕获的图像显示到图像视图
谢谢你的帮助。
答案 0 :(得分:0)
使用此代码。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage* Image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
[self previewImageOverlayView:Image];
}
-(void)previewImageOverlayView :(UIImage *)captureImage
{
CGRect deviceRect= [UIScreen mainScreen].bounds;
float screenHeight=deviceRect.size.height;
UIView *previewImageOveraLayView=[[UIView alloc] initWithFrame:deviceRect];
[previewImageOveraLayView setAutoresizesSubviews:NO];
UIImageView *previewImage=[[UIImageView alloc] init];
[previewImage setContentMode:UIViewContentModeScaleAspectFill];
[previewImage setFrame:CGRectMake(0,0,320,screenHeight-60)];
[previewImage setImage:captureImage];
[previewImageOveraLayView addSubview:previewImage];
UIButton *retakeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[retakeBtn addTarget:self action:@selector(useOrRetakeBtnPress:) forControlEvents:UIControlEventTouchUpInside];
[retakeBtn setBackgroundColor:[UIColor blackColor]];
[retakeBtn setTitle:@"Retake" forState:UIControlStateNormal];
[retakeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[retakeBtn setFrame:CGRectMake(0,screenHeight-60,160,60)];
[previewImageOveraLayView addSubview:retakeBtn];
UIButton *useBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[useBtn setTag:2000];
[useBtn addTarget:self action:@selector(useOrRetakeBtnPress:) forControlEvents:UIControlEventTouchUpInside];
[useBtn setBackgroundColor:[UIColor blackColor]];
[useBtn setTitle:@"Use" forState:UIControlStateNormal];
[useBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[useBtn setFrame:CGRectMake(160,screenHeight-60,160,60)];
[previewImageOveraLayView addSubview:useBtn];
[imagePicker.view addSubview:previewImageOveraLayView];
}
-(IBAction)useOrRetakeBtnPress:(UIButton*)sender
{
[sender.superview removeFromSuperview];
}
答案 1 :(得分:0)
您可以使用AVCapturSession而不是UIImagePickerController。您可以随意使用它并根据需要使用它。
的详细信息