Tuesday, July 28, 2009

Image packaged in a c program?

Ok, here is the situation! I have a program that copies an image from one location to another, but the problem is it will only work on a computer where that image exists. So I want to know if there is a way for me to somehow have the image with the program, so that all the user needs is the program, and the image will be part of the program. Kinda like how header files are included in a C program, only I want to include an image? If you need me to clarify I can. I am coding the program in C, but I can use Java if there is someway to do it in that language. Master_Furches@yahoo.com

Image packaged in a c program?
sure you can do that. you can compile the picture into your application. there are several ways to do that. if you're writing a windows application, you can add it as a Resource (same as i.e. icons, menus and dialogs). but maybe it's easier to just compile it as a binary array:





unsigned char imgdata[]={ 0x13, 0x84, 0xfa, 0xf0, ... };





use a hex editor to dump the image as hex data, then write the hex data into a char array. (or write a small program which opens the image file, reads it and writes each byte as a hex constant).





then you can use imgdata in your program, and sizeof(imgdata) gives you the size of the image.
Reply:C language usually comes with the standard library, which includes basic routines and drawings, but I don't think it has the moduls to carry the image files. There are a plenty of sites that offers a solution to doing this task. Try to search and see and I think it's quite big and 'stuffy' but if you just want to use it you can copy it and paste it and follow the instruction correctly. Well as for me, I think it's good to use Java as it has the complete library for the graphics and image processing as well as handling. It's easier to use, no need to install the third party library or extension to run.


No comments:

Post a Comment