iOS 图片扫描(Moodstocks)
来源:互联网 发布:锋锦网络 编辑:程序博客网 时间:2024/05/20 22:04
项目开发涉及到图片扫描(Moodstocks),鉴于网上比较少此类的开发文章,顺手写下开发步骤方便以后开发。
Moodstocks官网 : https://moodstocks.com/apps/
参考官方文档 : https://moodstocks.com/docs/ios/getting-started-small-image-database/
次例子项目 是直接扫描图片读取信息,如果要点击屏幕或点击按钮扫描图片读取信息则要根据官方另一文档开发。
下载官方项目例子 : https://moodstocks.com/downloads/
1、搭建开发环境,首先下载SDK : https://moodstocks.com/docs/ios/getting-started-small-image-database/
2、导入必要Frameworks:
3、在项目targets -》build settings -》Linking-》other linker flags改成-Objc。
4、环境已搭建好先bulid一下 确认项目不报错,下面直接上代码:
1)、在AppDelegate.h中导入
#import <Moodstocks/Moodstocks.h>
@property(nonatomic,strong)MSScanner *scanner;
2)、在AppDelegate.m中
#import "AppDelegate.h"
#define MS_API_KEY @"yxqbi2coobqbyc9xwrj8"
#define MS_API_SECRET @"1hFcyEnktFOLzObq"
//API KEY
//yxqbi2coobqbyc9xwrj8
//API SECRET
//1hFcyEnktFOLzObq
@interface AppDelegate ()
//{
// MSScanner *_scanner;
//}
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *path = [MSScannercachesPathFor:@"scanner.db"];
_scanner = [[MSScanneralloc]init];
[_scanneropenWithPath:pathkey:MS_API_KEYsecret:MS_API_SECRETerror:nil];
// [_scanner syncInBackground];
// Create the progression and completion blocks:
void (^completionBlock)(MSSync *,NSError *) = ^(MSSync *op,NSError *error) {
if (error)
NSLog(@"Sync failed with error: %@", [errorms_message]);
else
NSLog(@"Sync succeeded (%li images(s))", (long)[_scannercount:nil]);
};
void (^progressionBlock)(NSInteger) = ^(NSInteger percent) {
NSLog(@"Sync progressing: %li%%", (long)percent);
};
// Launch the synchronization
[_scannersyncInBackgroundWithBlock:completionBlockprogressBlock:progressionBlock];
return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application {
[_scannerclose:nil];
}
3)、在ViewController.h中
#import <Moodstocks/Moodstocks.h>
@propertyMSScanner *scanner;
4)、在ViewController.m中
#import "ViewController.h"
#include "AppDelegate.h"
#import "MBProgressHUD.h"
@interface ViewController () <MSAutoScannerSessionDelegate,UIActionSheetDelegate>
{
MSAutoScannerSession *_scannerSession;
}
@property (weak) IBOutlet UIView *videoPreview;(满屏的view)
@property (nonatomic,strong)AppDelegate *appDelegate;
@end
@implementation ViewController
staticint kMSResultTypes =MSResultTypeImage |
MSResultTypeQRCode |
MSResultTypeEAN13;
- (void)viewDidLoad {
[superviewDidLoad];
_appDelegate = (AppDelegate *)[[UIApplicationsharedApplication]delegate];
self.scanner = _appDelegate.scanner;
_scannerSession = [[MSAutoScannerSessionalloc]initWithScanner:_scanner];
_scannerSession.resultTypes =kMSResultTypes;
_scannerSession.delegate =self;
CALayer *videoPreviewLayer = [self.videoPreviewlayer];
[videoPreviewLayersetMasksToBounds:YES];
CALayer *captureLayer = [_scannerSessioncaptureLayer];
[captureLayersetFrame:[self.videoPreviewbounds]];
[videoPreviewLayerinsertSublayer:captureLayer
below:[[videoPreviewLayersublayers] objectAtIndex:0]];
[_scannerSessionstartRunning];
}
-(void)viewWillAppear:(BOOL)animated
{
[self.viewaddSubview:self.videoPreview];
}
- (void)dealloc
{
[_scannerSessionstopRunning];
}
- (void)sessionWillStartServerRequest:(id)scannerSession
{
MBProgressHUD *hud = [MBProgressHUDshowHUDAddedTo:self.viewanimated:YES];
hud.labelText =@"Searching...";
}
- (void)session:(id)scannerSession didFindResult:(MSResult *)result
{
[MBProgressHUDhideHUDForView:self.viewanimated:YES];
NSLog(@"-----==----- %@",result);
NSString *title = [resulttype] == MSResultTypeImage ?@"Image" : @"Barcode";
NSString *message = [NSStringstringWithFormat:@"%@:\n%@", title, [resultstring]];
UIActionSheet *aSheet = [[UIActionSheetalloc]initWithTitle:message
delegate:self
cancelButtonTitle:@"OK"
destructiveButtonTitle:nil
otherButtonTitles:nil];
[aSheetshowInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
[_scannerSessionresumeProcessing];
}
//旋转
//- (void)updateInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
//{
// [_scannerSession setInterfaceOrientation:interfaceOrientation];
//
// AVCaptureVideoPreviewLayer *captureLayer = (AVCaptureVideoPreviewLayer *) [_scannerSession captureLayer];
//
// captureLayer.frame = self.view.bounds;
//
// // AVCapture orientation is the same as UIInterfaceOrientation
// switch (interfaceOrientation) {
// case UIInterfaceOrientationPortrait:
// [[captureLayer connection] setVideoOrientation:AVCaptureVideoOrientationPortrait];
// break;
// case UIInterfaceOrientationPortraitUpsideDown:
// [[captureLayer connection] setVideoOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
// break;
// case UIInterfaceOrientationLandscapeLeft:
// [[captureLayer connection] setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
// break;
// case UIInterfaceOrientationLandscapeRight:
// [[captureLayer connection] setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
// break;
// default:
// break;
// }
//}
完成以上步骤,项目编译直接扫描图片就可以出来信息了。
附:
如果是在iOS7 版本一下环境下开发的项目,Xcode升级后在项目在iOS7运行会报错
解决办法:在项目targets -》build settings -》Build Options-》Enable Bitcode 的属性YES改成NO,如下图
转载请注明出处:http://blog.csdn.net/sevenquan/article/details/50684981
- iOS 图片扫描(Moodstocks)
- iOS 二维码 (包括扫描二维码,和读取二维码图片)
- iOS-AVFoundation二维码扫描,二维码扫描,图片的无损放大
- 扫描图片
- iOS Zbar获取相册本地图片扫描二维码
- iOS 扫描二维码、长按图片识别二维码
- ios二维码的生成与二维码图片的扫描
- iOS 二维码的扫描使用,以及图片预览,类似于相册
- iOS 原生二维码扫描(可限制扫描区域)
- iOS 原生二维码扫描(可限制扫描区域)
- iOS 原生二维码扫描(可限制扫描区域)
- iOS 原生二维码扫描(可限制扫描区域)
- iOS 原生二维码扫描(可限制扫描区域)
- iOS 原生二维码扫描(可限制扫描区域)
- iOS 原生二维码扫描(可限制扫描区域)
- iOS 原生二维码扫描(可限制扫描区域)
- 扫描SD卡里的图片(递归)
- 二维码生成、扫描、图片识别(Zxing)
- android通过秒换算成时分秒
- Python版本需要是2.7
- spring 数据源JNDI 基于tomcat mysql配置
- 获取软连接指定的真实文件名
- iOS开发:使用Block在两个界面之间传值(Block高级用法:Block传值)
- iOS 图片扫描(Moodstocks)
- 简单字典树Trie
- 证书的签发者无效的问题
- MQTT协议详解,非常易懂
- 使用极光推送实现分组发送和服务端集成
- iOS WebView与js通信
- Access denied for user 'root'@'localhost' (using password: YES)
- Android自定义对话框
- 深入Java虚拟机(1)——Java体系结构