Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Convert picture in to Objctive-C source code.
- # for example, to include an image in a static library.
- # original post : http://t.co/JqZmPyg4 @adnanced
- #
- # First step :
- # 1. Create a text file named pic2code.sh, and save it in your Documents folder.
- # 2. In the content of new text file, write script below:
- #!/bin/sh
- echo "// Byte array generated from file $1"
- echo "// date generated: `date`"
- echo
- echo "unsigned long $2_size=`stat -f %z $1`;"
- echo "unsigned char $2[] = {"
- od -t x1 $1 | sed "s/^[0-9]\{1,\} *//g" | sed "s/ *$//g" | sed "s/$/,/g" |
- sed "s/ \{1,\}/, 0x/g" | sed "s/^/0x/g" | sed "s/0x,//g"
- echo "};"
- # Second step :
- # 1. From Automator (use spotlight if dont'have in Application/Utility) create a new workflow.
- # 2. Add the finder item "Get Selected Items"
- # 3. Add a "Run Shell Script" item.
- # 4. In the Shell Script item, choose to pass input "as arguments", choose a Shell of "/bin/bash", and use the script below as the command text:
- for f in "$@"
- do
- y=${f/\/*\//}
- ~/Documents/pic2code.sh "$f" "${y/.*/}" > "${f%.*}.c"
- done
- # Last step :
- # 1. include the .c file in your project.
- # 2. where want to use it, declare external variables:
- #
- # extern unsigned long mypicname_size;
- # extern unsigned char mypicname[];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement