Advertisement
priore

Convert picture in to Objctive-C source code

Nov 30th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Convert picture in to Objctive-C source code.
  2. # for example, to include an image in a static library.
  3. # original post : http://t.co/JqZmPyg4 @adnanced
  4. #
  5. # First step :
  6. # 1. Create a text file named pic2code.sh, and save it in your Documents folder.
  7. # 2. In the content of new text file, write script below:
  8.  
  9. #!/bin/sh
  10. echo "// Byte array generated from file $1"
  11. echo "// date generated: `date`"
  12. echo
  13. echo "unsigned long $2_size=`stat -f %z $1`;"
  14. echo "unsigned char $2[] = {"
  15. od -t x1 $1 | sed "s/^[0-9]\{1,\} *//g" | sed "s/ *$//g" | sed "s/$/,/g" |
  16.    sed "s/ \{1,\}/, 0x/g" | sed "s/^/0x/g" | sed "s/0x,//g"
  17. echo "};"
  18.  
  19. # Second step :
  20. # 1. From Automator (use spotlight if dont'have in Application/Utility) create a new workflow.
  21. # 2. Add the finder item "Get Selected Items"
  22. # 3. Add a "Run Shell Script" item.
  23. # 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:
  24.  
  25. for f in "$@"
  26. do
  27.     y=${f/\/*\//}
  28.     ~/Documents/pic2code.sh "$f" "${y/.*/}" > "${f%.*}.c"
  29. done
  30.  
  31. # Last step :
  32. # 1. include the .c file in your project.
  33. # 2. where want to use it, declare external variables:
  34. #
  35. # extern unsigned long mypicname_size;
  36. # extern unsigned char mypicname[];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement