CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    4

    Img inside the code

    Hello all!!

    I have to code an .EXE app that loads an image and opens it with the default image handler of the system. Something like, two clicks on the .EXE program, it opens with an invisible window, copy the image from the code to the hard disk (or something like this), open this image and close itself.

    I know that this can be made with a big array of bytes, loaded into a buffer, etc.
    This is ok, but, when I need to change the image, it is not practical to change the entire buffer (hard coded into the code), compile again, and so on.

    There is some way, to just add the image to some project and compile the program?
    I'm actually a Java programmer, who needs to make this thing work =), so I'm using the C++ interface of netbeans.

    I've searched the forum and didn't find more information about this kind of thing I need.
    Can someone give me directions for this?
    Thank you very much!

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Img inside the code

    Well, of course you can write a program to take an image and generate a cpp file containing an array corresponding to it. That's the best I can think of.

  3. #3
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Img inside the code

    There are actually programs out there for you that already do that. GIMP comes to mind, from GIMP you can save as C code, C code works very nicely in C++.

  4. #4
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Img inside the code

    You caould add that image to your project's resource file, load it from resources at runtime and write to disk as a file.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  5. #5
    Join Date
    Apr 2009
    Posts
    4

    Re: Img inside the code

    Quote Originally Posted by VladimirF View Post
    You caould add that image to your project's resource file, load it from resources at runtime and write to disk as a file.
    Hi!

    But if I add to the project it will be placed somewhere inside the .EXE file?
    My go is to have one single .EXE file with all the stuff inside it.

    I tryed to to this, but the compiler doesn't seem to find the file, it always create another file in the root of the project...

    Thank you very much for the answers!!

  6. #6
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Img inside the code

    Use the char array spit out by gimp. That makes it much faster since there is no load time (but it will make your program start up slower.

  7. #7
    Join Date
    Apr 2009
    Posts
    4

    Re: Img inside the code

    Hey, thanks everyone!
    You helped me a lot!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured