我正在使用XZINGObjC框架来创建 EAN-Barcode-Image。按照文档,我正在这样做
//in viewDidAppear
//XZING: create Matrix
NSString* eanString = @"1234567890123"; //sth. like that
ZXBitMatrix* result = [writer encode:eanString
format:kBarcodeFormatEan13
width:500
height:500
error:&error];
if (result) {
//XZING: convert matrix to CGImageRef
CGImageRef imageRef = [[ZXImage imageWithMatrix:result] cgimage];
//CRASHLINE HERE!! (this is NOT in the XZING documentation, but i cannot figure out the issue!)
UIImage* uiImage = [[UIImage alloc] initWithCGImage:imageRef]; //<--CRASH: EXC_BAD_ACCESS
if(image != nil){
//assigning image to ui
self.barCodeImageView.image = uiImage;
}
如果我使用断点单步执行此代码,它就可以工作!但是,我认为在某些时候图像还没有准备好使用?!但我找不到原因。
我尝试了什么:
- 使用
imageRef
和uiImage
作为局部变量(EXC_BAD_ACCESS CRASH) - 在后台线程中尝试了该操作(EXC_BAD_ACCESS CRASH)
同样在这里,如果我使用断点并逐行执行代码,则每个解决方案都有效。我的错误是什么?有任何想法吗?提前致谢!