Skip to content

Instantly share code, notes, and snippets.

@clafferty-powa
Created January 6, 2016 20:32
Show Gist options
  • Select an option

  • Save clafferty-powa/fcef8da22fc8bd6a8bf2 to your computer and use it in GitHub Desktop.

Select an option

Save clafferty-powa/fcef8da22fc8bd6a8bf2 to your computer and use it in GitHub Desktop.
iOS Alpha Channel Signature Fix
UIImage *signatureImage = [UIImage imageNamed:@"testSignature.png"];
//Start an image context (the second param here “YES” says that the context won’t have any alpha channels)
UIGraphicsBeginImageContextWithOptions(signatureImage.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// Fill with white:
CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
CGContextFillRect(context, (CGRect){ {0,0}, signatureImage.size} );
// Fix coordinate system scaling and orientation.
CGContextTranslateCTM(context, 0, signatureImage.size.height);
CGContextScaleCTM(context, signatureImage.scale / [[UIScreen mainScreen]scale] , -signatureImage.scale / [[UIScreen mainScreen]scale]);
//Draw the image into the context:
CGContextDrawImage(context, (CGRect){ {0,0}, signatureImage.size}, [signatureImage CGImage]);
//Get the non-transparent image:
UIImage *image = [UIImage imageWithData:UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext())];
UIGraphicsEndImageContext();
[[self.powaPOS printer] printImage:[UIImage imageWithData:UIImagePNGRepresentation(image)]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment