Created
January 6, 2016 20:32
-
-
Save clafferty-powa/fcef8da22fc8bd6a8bf2 to your computer and use it in GitHub Desktop.
iOS Alpha Channel Signature Fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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