zoukankan      html  css  js  c++  java
  • 用UIImagePickerViewController自定义相机界面

    用UIImagePickerViewController自定义相机界面--原文地址

    1.设定imagePacker参数

    // Transform values for full screen support:

    #define CAMERA_TRANSFORM_X 1

    // this works for iOS 4.x

    #define CAMERA_TRANSFORM_Y 1.24299 

    -(void)viewWillAppear:(BOOL)animated{

        

        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

    imagePickerController.delegate = self;

    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

    imagePickerController.showsCameraControls = NO;

    imagePickerController.navigationBarHidden = YES;

    imagePickerController.wantsFullScreenLayout = YES;

    imagePickerController.cameraViewTransform =CGAffineTransformScale(imagePickerController.cameraViewTransform, CAMERA_TRANSFORM_X,CAMERA_TRANSFORM_Y);

        cameraViewController = [[CameraOverlayViewControlleralloc]initWithNibName:@"CameraOverlayViewController" bundle:nil];

        imagePickerController.cameraOverlayView = cameraViewController.view;

        cameraViewController.pickerController = imagePickerController;

        [self presentModalViewController:imagePickerController animated:NO];

        [imagePickerController release];

    }

    2.代理方法

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

        [picker dismissModalViewControllerAnimated:NO];

        UIImage* image = [info valueForKey:UIImagePickerControllerOriginalImage];

        BeautifyPhotoViewController* beautifyPhotoViewController = [[BeautifyPhotoViewController alloc]initWithNibName:@"BeautifyPhotoViewController" bundle:nil];

        beautifyPhotoViewController.photoImage = image;

        [self.navigationController pushViewController:beautifyPhotoViewController animated:YES];

        [beautifyPhotoViewController release];

    }

    3.overlayView对应的controller

    #import "CameraOverlayViewController.h"

    @interface CameraOverlayViewController ()

    @end

    @implementation CameraOverlayViewController

    @synthesize pickerController;

    @synthesize cameraScaleBtn;

    @synthesize titleImageView;

    @synthesize flashModeBtn;

    @synthesize deviceModeBtn;

    @synthesize photoBtn;

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            // Custom initialization

            [self getAllPhotoImages];

        }

        return self;

    }

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        isOneToOne = YES;

        imageArray = [[NSMutableArray alloc]init];

        shadowView = [[ShadowView alloc]initWithRect:CGRectMake(0, 80, 320, 320)];

        [self.view addSubview:shadowView];

        [self.view sendSubviewToBack:shadowView];

        [shadowView release];

        // Do any additional setup after loading the view from its nib.

    }

    - (void)viewDidUnload

    {

        [super viewDidUnload];

        // Release any retained subviews of the main view.

        // e.g. self.myOutlet = nil;

    }

    //闪光灯

    -(IBAction)cameraTorchOn:(id)sender{

        if (pickerController.cameraFlashMode ==UIImagePickerControllerCameraFlashModeAuto) {

            pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;

        }else {

            pickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;

        }

    }

    //前后摄像头

    - (IBAction)swapFrontAndBackCameras:(id)sender {

        if (pickerController.cameraDevice ==UIImagePickerControllerCameraDeviceRear ) {

            pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;

        }else {

            pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;

        }

    }

    //改变拍摄比例

    -(IBAction)changeCameraScale:(id)sender{

        if (isOneToOne) {

            [shadowView changeRect:CGRectMake(0, 0, 320, 428)];

            [cameraScaleBtn setImage:[UIImage imageNamed:@"font_-scale43.png"]forState:UIControlStateNormal];

            titleImageView.alpha = 0.2;

            flashModeBtn.alpha = 0.5;

            deviceModeBtn.alpha = 0.5;

            isOneToOne = NO;

        }else {

            [shadowView changeRect:CGRectMake(0, 80, 320, 320)];

            [cameraScaleBtn setImage:[UIImage imageNamed:@"font_-scale11.png"]forState:UIControlStateNormal];

            titleImageView.alpha = 1;

            flashModeBtn.alpha = 1;

            deviceModeBtn.alpha = 1;

            isOneToOne = YES;  

        }

    }

    - (IBAction)enterPhotoAlbum:(id)sender {

        PhotoAlbumViewController* photoAlbumViewController = [[PhotoAlbumViewControlleralloc]initWithNibName:@"PhotoAlbumViewController" bundle:nil];

        [self presentModalViewController:photoAlbumViewController animated:YES];

        

    }

    //拍摄照片

    -(IBAction)takeThePic:(id)sender{

        [pickerController takePicture];

    }

    -(IBAction)backToHome:(id)sender{

        [pickerController dismissModalViewControllerAnimated:NO];

        [[NSNotificationCenter defaultCenter] postNotificationName:@"backToHome" object:nil];

    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

    {

        return (interfaceOrientation == UIInterfaceOrientationPortrait);

    }

    - (void)dealloc

    {

        [cameraScaleBtn release];

        [flashModeBtn release];

        [deviceModeBtn release];

        [titleImageView release];

        [super dealloc];

    }

    -(void)getAllPhotoImages{

        ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror){

            

            NSLog(@"error occour =%@", [myerror localizedDescription]);

        };

        ALAssetsGroupEnumerationResultsBlock groupEnumerAtion = ^(ALAsset *result, NSUInteger index,BOOL *stop){

            if (result!=NULL) {

                if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {

                    [imageArray addObject:result];

                    UIImage *img=[UIImage imageWithCGImage:result.thumbnail];

                    [photoBtn setImage:img forState:UIControlStateNormal];

                }

            }

        };

        ALAssetsLibraryGroupsEnumerationResultsBlock

        

        libraryGroupsEnumeration = ^(ALAssetsGroup* group, BOOL* stop){

            

            if (group == nil) {

                return;

            }

            if (group!=nil) {

                [group enumerateAssetsUsingBlock:groupEnumerAtion];

            }

        };

        ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];

        

        [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos

         

                               usingBlock:libraryGroupsEnumeration 

         

                             failureBlock:failureblock];

        [library release];

    }

    @end

  • 相关阅读:
    思考题回答
    Winform中DevExpress的TreeList的入门使用教程(附源码下载)
    感兴趣的开源项目列表Java 标签: jfreechart报表引擎图表制作eclipsejavabeans 20080325 11:20 466人阅读
    试用GNU Gettext 开源多语组件包 标签: delphi语言file文本编辑domainstring 20080428 17:54 1330人阅读
    DDK Source Files Allot 标签: ddk测试 20080917 16:03 312人阅读 评论(0)
    Philip 190SW8 LCD 设置 标签: 游戏 20080713 14:45 515人阅读 评论(0)
    爆笑:两分钟让你明白什么是ERP! 标签: 电话工作平台产品 20080326 13:45 311人阅读 评论(0)
    通过控件移动窗体 标签: integer 20080520 16:13 342人阅读 评论(0) 收藏
    Google Web Toolkit 真的至关重要? 标签: googlewebjavascriptgwtajax平台 20080325 09:47 273人阅
    我的Eclipse插件列表 标签: eclipse插件eclipselog4jpropertiestomcattools 20080324 15:11 477人
  • 原文地址:https://www.cnblogs.com/poky/p/5306957.html
Copyright © 2011-2022 走看看