Last active
August 29, 2015 14:26
-
-
Save zhangao0086/6d65bc9253b289a30661 to your computer and use it in GitHub Desktop.
Convert image to hex
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
// Objective-C | |
UIImage *image = [UIImage imageNamed:<#(NSString *)#>]; | |
NSData *imageData = UIImagePNGRepresentation(image); | |
NSInteger len = imageData.length; | |
Byte *bytes = (Byte *)[imageData bytes]; | |
NSMutableString *result = [NSMutableString stringWithCapacity:len * 5]; | |
[result appendString:@"{"]; | |
for (NSUInteger i = 0; i < len; i++) { | |
if (i) { | |
[result appendString:@","]; | |
} | |
[result appendFormat:@"0x%x", bytes[i]]; | |
} | |
[result appendString:@"}"]; | |
NSLog(@"%@", result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment