WatchKit: image not shown

Here are the codes:

@interface InterfaceController()
@property (nonatomic, weak) IBOutlet WKInterfaceImage *qrImage;
@property (nonatomic, weak) IBOutlet WKInterfaceLabel *label;
@end

@implementation InterfaceController
- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];
    [self.label setText: @"Welcome"];
    UIImage *image = [InterfaceController generateQRCodeWithString:@"Welcome"];
    [self.qrImage setImage:image];
}

- (void)willActivate {
    [super willActivate];
}

- (void)didDeactivate {
    [super didDeactivate];
}

+ (UIImage *)generateQRCodeWithString:(NSString *)string {
    NSData *stringData = [string dataUsingEncoding:NSUTF8StringEncoding];
    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
    [filter setValue:stringData forKey:@"inputMessage"];
    [filter setValue:@"M" forKey:@"inputCorrectionLevel"];

    CIImage *input = filter.outputImage;
    CGAffineTransform transform = CGAffineTransformMakeScale(10.0f, 10.0f);
    CIImage *output = [input imageByApplyingTransform: transform];

    return [UIImage imageWithCIImage:output];
}
@end

I am trying to generate a QR code from a specific text and display it in the clock interface. The problem is that the UIImage generated generateQRCodeWithString:is never displayed. However, if I upload an image using the [UIImage imageNamed:@"XXX.png"]WatchKit extension package, it displays correctly.

I'm not sure what is going on. What am I missing? Thanks in advance.


UPDATE: In response to msk, yes, I'm sure. I tried NSLog image, it gives<UIImage: 0x7fc261d276e0>, {230, 230}

+4
source share
1 answer

, generateQRCodeWithString:, "" () . CIImage , , .

return generateQRCodeWithString: :

CGImageRef cgOutput = [[CIContext contextWithOptions:nil]
                       createCGImage:output fromRect:output.extent];
return [UIImage imageWithCGImage:cgOutput];

QR- CGImage, , UIImage.

CIContext , QR-, - . , .

+2

All Articles