私の問題は次のとおりです。ZXingObjCでデータ行列を生成して表示したい。Swift 2とZXingObjCでデータマトリックスを生成
現在、私はXCode 7.3とSwift 2.haveを使用してアプリケーションを作成し、String値を持つデータ行列を生成しています。客観Cで書かれZXingObjCが、私はこの例によれば、それを自分自身を変換しようとしたとして:
NSError *error = nil; ZXMultiFormatWriter *writer = [ZXMultiFormatWriter writer]; ZXBitMatrix* result = [writer encode:@"A string to encode" format:kBarcodeFormatQRCode width:500 height:500 error:&error]; if (result) { CGImageRef image = [[ZXImage imageWithMatrix:result] cgimage]; } else { NSString *errorMessage = [error localizedDescription]; }
私はwriter.encode(...)と私の文字列をエンコードしようと、私はそれがだと思うと、問題が発生し私は長いと小さい文字列で試したが、結果は同じままです。
do { let writer = ZXMultiFormatWriter() let hints = ZXEncodeHints() as ZXEncodeHints let result = try writer.encode("foo", format: kBarcodeFormatDataMatrix, width: 300, height: 300, hints: hints) let imageRef = ZXImage.init(matrix: result) picture.image = UIImage(CGImage: imageRef.cgimage) } catch { print(error) }
そして最後に、この例外を持つアプリのクラッシュ:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't find a symbol arrangement that matches the message. Data codewords: 17' *** First throw call stack: ( 0 CoreFoundation 0x00000001081b7d85 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010854cdeb objc_exception_throw + 48 2 CoreFoundation 0x00000001081b7cbd +[NSException raise:format:] + 205 3 ZXingObjC 0x0000000107eb320a +[ZXDataMatrixSymbolInfo lookup:shape:minSize:maxSize:fail:] + 1178 4 ZXingObjC 0x0000000107ead4bb -[ZXDataMatrixEncoderContext updateSymbolInfoWithLength:] + 379 5 ZXingObjC 0x0000000107ea2866 -[ZXDataMatrixC40Encoder encode:] + 342 6 ZXingObjC 0x0000000107eaf032 +[ZXDataMatrixHighLevelEncoder encodeHighLevel:shape:minSize:maxSize:] + 1330 7 ZXingObjC 0x0000000107eb75b0 -[ZXDataMatrixWriter encode:format:width:height:hints:error:] + 672 8 ZXingObjC 0x0000000107ee246c -[ZXMultiFormatWriter encode:format:width:height:hints:error:] + 1100 9 DemoAppZXing 0x0000000103f54d98 _TFC4DemoAppZXing27VSMatrixOrderViewController11viewDidLoadfT_T_ + 8472 10 DemoAppZXing 0x0000000103f58002 _TToFC4DemoAppZXing27VSMatrixOrderViewController11viewDidLoadfT_T_ + 34 11 UIKit 0x0000000106a95984 -[UIViewController loadViewIfRequired] + 1198 12 UIKit 0x0000000106a9b93b -[UIViewController __viewWillAppear:] + 120 13 UIKit 0x0000000106acb750 -[UINavigationController _startCustomTransition:] + 1203 14 UIKit 0x0000000106adbb9b -[UINavigationController _startDeferredTransitionIfNeeded:] + 712 15 UIKit 0x0000000106adcd0b -[UINavigationController __viewWillLayoutSubviews] + 57 16 UIKit 0x0000000106c8b503 -[UILayoutContainerView layoutSubviews] + 248 17 UIKit 0x00000001069b5980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703 18 QuartzCore 0x000000010a2bfc00 -[CALayer layoutSublayers] + 146 19 QuartzCore 0x000000010a2b408e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 20 QuartzCore 0x000000010a2b3f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 21 QuartzCore 0x000000010a2a83c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 22 QuartzCore 0x000000010a2d6086 _ZN2CA11Transaction6commitEv + 486 23 UIKit 0x00000001068f572e _UIApplicationHandleEventQueue + 7135 24 CoreFoundation 0x00000001080dd301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 25 CoreFoundation 0x00000001080d322c __CFRunLoopDoSources0 + 556 26 CoreFoundation 0x00000001080d26e3 __CFRunLoopRun + 867 27 CoreFoundation 0x00000001080d20f8 CFRunLoopRunSpecific + 488 28 GraphicsServices 0x000000010a8a1ad2 GSEventRunModal + 161 29 UIKit 0x00000001068faf09 UIApplicationMain + 171 30 DemoAppZXing 0x0000000103f60ec2 main + 114 31 libdyld.dylib 0x000000010905492d start + 1 ) libc++abi .dylib: terminating with uncaught exception of type NSException
を編集:
この問題を解決するために、私はちょうどに、minSizeおよびmaxSizeのを設定する必要があります。
[ZXDataMatrixSymbolInfo検索:形状:に、minSize:maxSizeの:失敗:] + 1178'、私は、以前の設定で欠けている値か、ヒントのヒントの中にある可能性が高い値を疑うでしょう。 –
この場合、以前の設定はありません。しかし、それでも私が何かを忘れた場合、私は何ができるかわかりません。 –