2017-02-28 15:15:52 tanhao09 阅读数 437

因业务需求需要做一个微信上墙的功能,但是实测的时候发现页面上显示iOS拍照上传的图片时图像旋转了90度.

查了很多资料很多都是借用这个方法java处理iPhone拍照后图片EXIF属性翻转90度的方法,但是发现文中的方法 metadata.getDirectory(ExifIFD0Directory.class);在源码中没有找到不知道是不是新版本的jra包换了新的方法,后来按照逻辑写出来了,但是还是不能成功的解决我的问题所以换了一个方法.因为项目是微信公众号的一个H5聊天页面与上墙页面显示所以需要生成缩略图,发现生成的缩略图并没有出现翻转的情况出现,所以取巧生成缩略图的同时生成了一个与原图1比1的图片在服务器.结果成功避开了这个问题,当这是取巧的方法,大家有其他方法可以写出来方便大家参考.生成缩略图使用了这个方法Thumbnails生成缩略图

2016-12-30 21:37:10 jinweiyi_tse 阅读数 840
iOS拍照识别车牌技术SDK

  iOS拍照识别车牌技术描述

  iOS拍照识别车牌技术是文通开发的基于移动平台的车牌识别软件开发包,支持android、ios等多种主流移动操作系统。该产品采用手机、平板电脑摄像头拍摄汽车牌照图像,然后通过OCR软件对车牌颜色、车牌号进行识别。

(iOS拍照识别车牌技术-演示demo)

  iOS拍照识别车牌技术技术功能

  1. 整牌识别率高达99.7%,尤其汉字识别遥遥领先同类产品;

  2. 识别速度快,极致优化的车牌定位和识别算法;

  3. 支持牌照全,包括蓝牌、黄牌(双)、军牌(双)、武警牌(双)、警牌、农用车牌、教练车牌、大使馆等各种规格牌照;

  4. 车牌宽度要求低,车牌宽度≥70个像素,都不影响识别;

  5. 纯C代码编写,可以跨平台应用。

  iOS拍照识别车牌技术配置要求

  1. 操作系统:支持android2.3以上版本;支持ios6.0及以上

  2. 摄像头:支持自动对焦,200万像素以上。

  3. 安装程序占用空间,3MBytes

  iOS拍照识别车牌技术拍摄规范

  规范的拍摄有助于提高识别率

  1. 保持水平,尽量使车牌在画面中保持水平;

  2. 合理光照,拍摄时注意光照的影响,尽量避免反光和黑影;

  3. 避免倾斜,不要使拍摄角度倾斜过大,以免造成车牌严重变型;

  4. 聚焦清晰,避免图像模糊不清楚。

  iOS拍照识别车牌技术典型应用

  智慧停车:互联网停车

  警务通:巡逻执勤、交警执法

  车辆保险:车险移动查勘,

  占道停车管理:占道停车收费

  运营人员 谢常胜 微信[13829771132] 转载前须与本人联系!!

2019-08-20 10:00:42 feiyangkl 阅读数 219

#iOS拍照后图片翻转

iOS拍照后图片自动翻转,是Image有一个imageOrientation属性,里面有图片拍照的方法,只要在拍照后的代理方法中,将返回的图片在翻转回来就可以了。

代码如下:



// 判断图片是否翻转
- (UIImage *)fixOrientation:(UIImage *)aImage {
    
    // No-op if the orientation is already correct
    if (aImage.imageOrientation == UIImageOrientationUp)
        return aImage;
    
    // We need to calculate the proper transformation to make the image upright.
    // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
    CGAffineTransform transform = CGAffineTransformIdentity;
    
    switch (aImage.imageOrientation) {
        case UIImageOrientationDown:
        case UIImageOrientationDownMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height);
            transform = CGAffineTransformRotate(transform, M_PI);
            break;
            
        case UIImageOrientationLeft:
        case UIImageOrientationLeftMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
            transform = CGAffineTransformRotate(transform, M_PI_2);
            break;
            
        case UIImageOrientationRight:
        case UIImageOrientationRightMirrored:
            transform = CGAffineTransformTranslate(transform, 0, aImage.size.height);
            transform = CGAffineTransformRotate(transform, -M_PI_2);
            break;
        default:
            break;
    }
    
    switch (aImage.imageOrientation) {
        case UIImageOrientationUpMirrored:
        case UIImageOrientationDownMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
            transform = CGAffineTransformScale(transform, -1, 1);
            break;
            
        case UIImageOrientationLeftMirrored:
        case UIImageOrientationRightMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.height, 0);
            transform = CGAffineTransformScale(transform, -1, 1);
            break;
        default:
            break;
    }
    
    // Now we draw the underlying CGImage into a new context, applying the transform
    // calculated above.
    CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,
                                             CGImageGetBitsPerComponent(aImage.CGImage), 0,
                                             CGImageGetColorSpace(aImage.CGImage),
                                             CGImageGetBitmapInfo(aImage.CGImage));
    CGContextConcatCTM(ctx, transform);
    switch (aImage.imageOrientation) {
        case UIImageOrientationLeft:
        case UIImageOrientationLeftMirrored:
        case UIImageOrientationRight:
        case UIImageOrientationRightMirrored:
            // Grr...
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage);
            break;
            
        default:
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage);
            break;
    }
    
    // And now we just create a new UIImage from the drawing context
    CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
    UIImage *img = [UIImage imageWithCGImage:cgimg];
    CGContextRelease(ctx);
    CGImageRelease(cgimg);
    return img;
}
2013-08-10 20:49:23 changyou0730 阅读数 1179

 

1CamerViewController.h文件

#import <UIKit/UIKit.h>

#import "CaptureViewController.h"

#import "PassImageDelegate.h"

 

@interfaceCamerViewController : UIViewController<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,PassImageDelegate,UIPopoverControllerDelegate>{

   

    UIPopoverController*myPopoverController;

    UIButton* choosePicture;

 

}

 

@property(nonatomic,retain)UIPopoverController *myPopoverController;

@property(nonatomic,retain)IBOutlet UIButton*choosePicture;

 

- (IBAction)choseButtonClicked:(id)sender;

 

-(UIImage *)scaleImage:(UIImage*)image toScale:(float)scaleSize;

-(BOOL)saveToDocument:(UIImage*) image withFilePath:(NSString *) filePath;

-(NSString *)imageSavedPath:(NSString *) imageName;

@end

 

 

 

 

 

2 CamerViewController.m文件

#import "CamerViewController.h"

 

@interface CamerViewController ()

{

    UIImageView*imageView;

}

 

 

@end

 

@implementationCamerViewController

 

@synthesizemyPopoverController;

@synthesizechoosePicture;

 

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

{

    self = [super initWithNibName:nibNameOrNilbundle:nibBundleOrNil];

    if (self) {

        // Custominitialization

    }

    return self;

}

 

- (void)viewDidLoad

{

    [super viewDidLoad];

   

    //初始化显示截取后图片的ImageView

    //imageView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 100, 320, 320)];

    //imageView.image= [UIImage imageNamed:@"transparencyPattern"];

    //[self.viewaddSubview:imageView];

   

}

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose ofany resources that can be recreated.

}

 

 

 

//弹出选项列表选择图片来源

- (IBAction)choseButtonClicked:(id)sender {

    UIActionSheet*chooseImageSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera",@"Photolibrary", nil];

    [chooseImageSheet showInView:self.view];

    [chooseImageSheet release];

   

}

 

 

 

#pragmamark UIActionSheetDelegate Method

-(void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

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

    picker.delegate= self;

   

    switch(buttonIndex) {

        case0://Take picture

           

         if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){

             picker.sourceType= UIImagePickerControllerSourceTypeCamera;

             picker.cameraDevice= UIImagePickerControllerCameraDeviceFront;

             picker.cameraOverlayView= self.view;

            

             if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

                 UIPopoverController*popoverController1=[[UIPopoverController alloc] initWithContentViewController:picker];

                 popoverController1.delegate = self;

                 self.myPopoverController = popoverController1;

                 //[popoverController presentPopoverFromRect:self.choosePicture.boundsinView:self.view permittedArrowDirections:UIPopoverArrowDirectionAnyanimated:YES];

                

                 [popoverController1 release];

             }

             else{

                 [selfpresentViewController:picker animated:YES completion:nil];

             }

 

                    

         }else{

                    NSLog(@"模拟器无法打开相机");

         }

           

       

         break;

           

           

        case1://From album

           

          

            picker.sourceType= UIImagePickerControllerSourceTypePhotoLibrary;

            if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

                UIPopoverController*popoverController=[[UIPopoverController alloc] initWithContentViewController:picker];

                popoverController.delegate= self;

                [popoverController presentPopoverFromRect: self.view.frame

                                                  inView:self.view

                                 permittedArrowDirections:UIPopoverArrowDirectionAny

                                                animated:YES];

                self.myPopoverController = popoverController;

               

                [popoverController release];

 

               

            }

            else{

                [selfpresentViewController:picker animated:YES completion:nil];

            }

 

           

            break;

           

        default:

           

            break;

    }

}

 

#pragma 拍照选择照片协议方法

-(void) imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary*)info

{

 

    [UIApplicationsharedApplication].statusBarHidden= NO;

   

    NSString*mediaType = [info objectForKey:UIImagePickerControllerMediaType];

   

    NSData*data;

   

    if([mediaType isEqualToString:@"public.image"]){

       

        //切忌不可直接使用originImage,因为这是没有经过格式化的图片数据,可能会导致选择的图片颠倒或是失真等现象的发生,从UIImagePickerControllerOriginalImage中的Origin可以看出,很原始,哈哈

        UIImage*originImage = [info objectForKey:UIImagePickerControllerOriginalImage];

       

        //图片压缩,因为原图都是很大的,不必要传原图

        UIImage*scaleImage = [self scaleImage:originImagetoScale:0.3];

       

        //以下这两步都是比较耗时的操作,最好开一个HUD提示用户,这样体验会好些,不至于阻塞界面

        if (UIImagePNGRepresentation(scaleImage) == nil) {

            //将图片转换为JPG格式的二进制数据

            data = UIImageJPEGRepresentation(scaleImage,1);

        } else{

            //将图片转换为PNG格式的二进制数据

            data = UIImagePNGRepresentation(scaleImage);

        }

     

        //将二进制数据生成UIImage

        UIImage*image = [UIImage imageWithData:data];

       

        //将图片传递给截取界面进行截取并设置回调方法(协议)

        CaptureViewController*captureView = [[CaptureViewController alloc] init];

        captureView.delegate= self;

        captureView.image= image;

        //隐藏UIImagePickerController本身的导航栏

        picker.navigationBar.hidden = YES;

        [picker pushViewController:captureViewanimated:YES];

       

    }

 

}

 

 

//根据图片名将图片保存到ImageFile文件夹中

-(NSString *)imageSavedPath:(NSString *) imageName

{

    //获取Documents文件夹目录

    NSArray*path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString*documentPath = [path objectAtIndex:0];

    //获取文件管理器

    NSFileManager*fileManager = [NSFileManager defaultManager];

    //指定新建文件夹路径

    NSString*imageDocPath = [documentPath stringByAppendingPathComponent:@"ImageFile"];

   

    //创建ImageFile文件夹

    [fileManager createDirectoryAtPath:imageDocPathwithIntermediateDirectories:YES attributes:nil error:nil];

    //返回保存图片的路径(图片保存在ImageFile文件夹下)

    NSString* imagePath = [imageDocPath stringByAppendingPathComponent:imageName];

    returnimagePath;

}

 

//将选取的图片保存到目录文件夹下

-(BOOL)saveToDocument:(UIImage*) image withFilePath:(NSString *) filePath

{

    if((image == nil) || (filePath == nil) || [filePath isEqualToString:@""]) {

        returnNO;

    }

   

    @try {

        NSData*imageData = nil;

        //获取文件扩展名

        NSString*extention = [filePath pathExtension];

        if([extention isEqualToString:@"png"]) {

            //返回PNG格式的图片数据

            imageData = UIImagePNGRepresentation(image);

        }else{

            //返回JPG格式的图片数据,第二个参数为压缩质量:0:best1:lost

            imageData = UIImageJPEGRepresentation(image, 0);

        }

        if(imageData == nil || [imageData length] <= 0){

            returnNO;

        }

        //将图片写入指定路径

        [imageData writeToFile:filePathatomically:YES];

        return  YES;

    }

    @catch(NSException *exception) {

        NSLog(@"保存图片失败");

    }

   

    return NO;

   

}

 

 

 

#pragmamark - 图片回传协议方法

-(void)passImage:(UIImage*)image

{

    imageView.image = image;

   

    //method 1:保存相片至新建文件夾

    // NSString*imagePath = [self imageSavedPath:@"image.png"];

    // BOOLisSaveSuccess = [self saveToDocument:imageView.image withFilePath:imagePath];

   

    //method 2:保存相片至"My Files"文件夾

    BOOLisSaveSuccess = [self saveToDocument:imageView.image withFilePath:CURRENT_USER_FOLDER];

   

    if(isSaveSuccess) {

        UIAlertView*alertView = [[UIAlertView alloc] initWithTitle:@"操作结果" message:@"保存图片成功" delegate:self cancelButtonTitle:@"OK"otherButtonTitles:nil, nil];

        [alertView show];

        [alertView release];

    }else {

        UIAlertView*alertView = [[UIAlertView alloc] initWithTitle:@"操作结果" message:@"保存图片失败" delegate:self cancelButtonTitle:@"OK"otherButtonTitles:nil, nil];

        [alertView show];

        [alertView release];

    }

   

 

    UIImageWriteToSavedPhotosAlbum([imageView image],nil, nil,nil);

 

}

 

#pragmamark- 缩放图片

-(UIImage *)scaleImage:(UIImage*)image toScale:(float)scaleSize

{

    UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));

    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];

    UIImage*scaledImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    returnscaledImage;

}

 

 

 

@end

 

 

 

 

2019-07-18 19:17:19 github_38057462 阅读数 29

只需记住:

1.iOS拍照默认的照片方向并不是竖着拿手机时的情况,而是横向,即Home键在右侧;

2.android拍照默认的照片方向并不是竖着拿手机的;

3.主要是获取图片的EXIF头部信息,其中有一个叫做Orientation (rotation)的标签,用于记录图像的方向,这便是相机写入方向信息的最终位置。它总共定义了八个值:
在这里插入图片描述

4.对应的修改可以iOS处理也可以前端处理,推荐源头iOS进行处理简单;

推荐这篇文章,介绍的很详细

iOS拍照界面,复制、粘贴等英文转中文

博文 来自: huxinguang_ios

ios 拍照与摄像

阅读数 853

没有更多推荐了,返回首页