ios - UIImageJPEGRepresentation returns nil (on a device - OK on Simulator) -
i nil on ios device (works ok on simulator or playground) when create create barcode uiimage generatebarcode("abcdef") , call uiimagejpegrepresentation or uiimagepngrepresentation.
there still wrong in uiimage debugger cannot display uiimage either. image exists, cgimage property set uiimagejpegrepresentation doesn't it.
i have tried solve per: uiimagejpegrepresentation returns nil
class func generatebarcode(from string: string) -> uiimage? { let data = string.data(using: string.encoding.ascii) if let filter = cifilter(name: "cicode128barcodegenerator") { filter.setvalue(data, forkey: "inputmessage") if let ciimage = filter.outputimage { if let cgimange = convertciimagetocgimage(inputimage: ciimage) { return uiimage(cgimage: cgimange) } } } return nil } class func convertciimagetocgimage(inputimage: ciimage) -> cgimage? { let context = cicontext(options: nil) if let cgimage = context.createcgimage(inputimage, from: inputimage.extent) { return cgimage } return nil }
Comments
Post a Comment