Contribute  :  Calendar  :  Advanced Search  :  Site Statistics  :  Directory  :  Files to download  :  Links for developers  :  Privacy policy  :  Web Resources  :  Polls  
    MacOSX Guru Site Information, tips and tricks, FAQ for Mac OS X developers    
 Welcome to MacOSX Guru Site
 Saturday, March 23 2019 @ 11:21 PM UTC

How to embed an image in application's source code ?

Objective-CIf you don't want the image to be accessible in the application bundle or if the image has to be in a command line tool (without bundle): how do you embed an image in the source code - kind of static NSData ?

Download here a small command line tool (Universal) that let's you convert any file content into a char buffer.

file2ctsr < myimage > myimage.c
file2ctsr < myimage > myimage.m
file2ctsr -p variableName myImage >  myimage.cpp
are typical usages.
The image.X source file will contain something like:

char *buffer0 = "\376\355\372\316\000\000\000\022\000\000\000\000\000\000\000\002\000\000\000\012\000\000\005\104\000\000\000\205\000\000\000\001"
size_t buffer0Len = 18052 ;

If you want to use it as the data source for an image in a Cocoa application:

NSImage *myImage = [[NSImage alloc] initWithData:[NSData dataWithBytes:buffer0 length:buffer0Len]] ;

What's Related

Story Options

How to embed an image in application's source code ? | 1 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
How to embed an image in application's source code ?
Authored by: Admin on Monday, March 13 2006 @ 06:22 PM UTC
xxd -include PATH_TO_IMAGE
is another solution.
 Copyright © 2019 MacOSX Guru Site
 All trademarks and copyrights on this page are owned by their respective owners.
Powered By Geeklog 
Created this page in 0.07 seconds