Thread: Using jpg images whit C

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    1

    Cool Using jpg images whit C

    Hello I am new to programming, and I have to do program in c that uses pictures and I want to re size the console window, but for some reason i get a bunch linker errors(I have no clue how to fix those). I Have to use the graphics.h Library and Devc++

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <graphics.h>
    #include <string.h>
    
    
    void Display(void)
    { 
      readimagefile("Inicio.jpg",20,200,200,400);
      //readimagefile("c2.jpg",1140,200,1340,400);
      //readimagefile("cr.jpg",1000,600,1340,700);
      //readimagefile("logo.jpg",400,200,940,700); 
    }
    int main(  )
    {  
      initwindow( 1280, 768, "Invent" );
      Display();
      
      return 0;
    }
    I already have libbgi.a in the folder devcpp/lib and graphics.h in devcpp/include
    -lbgi
    -lgdi32
    -lcomdlg32
    -luuid
    -loleaut32
    -lole32
    I already set up the parameters and the pictures are in the same folder as the program can someone tell me what i am doing wrong, do I need to do something more??? or did I messed up somewhere in the parameters area??

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The console window is a text based window, quite unsuitable to try and display a picture. You need a graphics window, and it has to be one that is supported by your compiler or library, and current operating system.

    Do you know what graphics windows your system will now create?

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    DevC++ is windows only...

    BGI graphics died with Win2000 when Windows stopped allowing direct access to hardware (and particularly video hardware). Under Vista and Win7 it is no longer possible to have a full screen DOS window with video mode switching (at least not without some serious messing about with the system) and if the OS is 64 bits it's entirely likely the program wouldn't run anyway.

    Our OP friend needs to pay a visit to TheForger and he needs to update his compiler to something that is not horridly outdated

    (@OP... yes the red bits are links... click on them)

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    BGI graphics work fine in Windows XP (x32 bit), with the default installation. That's one reason I stuck with Turbo C for such a long time.

    Is that what devC used, BGI graphics?

    In Windows 7 or Vista (x64 bit), you can run them (I'm told), by using DOSBox to set up the virtual environment. I have never tried this however.

    Nothing on Google about it?

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    BGI graphics work fine in Windows XP (x32 bit), with the default installation. That's one reason I stuck with Turbo C for such a long time.

    Is that what devC used, BGI graphics?

    In Windows 7 or Vista (x64 bit), you can run them (I'm told), by using DOSBox to set up the virtual environment. I have never tried this however.

    Nothing on Google about it?
    Sigh... more "old think"... Why on earth would you butcher a modern operating system into looking like a quarter century old antique?

    The best and probably easiest way is to move up to GUI mode programming and CGI (or better) graphics using the real-deal message/event driven API. Not only will it be faster, it will actually do stuff console mode can't. *Nobody* writes console code anymore, except during training and (rarely) for quicky utility programs. Even the most basic GUI mode stuff makes console code look, well, stupid.

    To give you but one of many examples... compare user input via an edit child to fgets() or scanf()... it's simply no contest.

    Heck, I'd never even written a Windows console program in C until I started helping out on these forums... and when working with Pascal I don't think I ever did.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'm NOT recommending BGI graphics, just saying that it works on Windows XP, not just on Windows2000.

    That is all.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    I'm NOT recommending BGI graphics, just saying that it works on Windows XP, not just on Windows2000.

    That is all.
    OK... (EDIT: I just re-read my message and realize you could have misunderstood my point... sorry about that)

    The message for the OP is that he would do well to learn GUI mode programming anyway since it is very likely any application he creates (either professionally or as freeware/shareware) is going to have to be windowed if he expects people to use it.

    Recent experience... I wrote a quick and dirty disk scanner for a client who's updating all his drives (500gb out, 2.5tb in 30+ drives). All it was supposed to do was open each file and read it from end to end to ensure a good copy was made during the transfer, so I just built a quick and dirty console app and put it in his folder for him to pick up on the VPN... Next morning I gets a phone call... "We got your program but nobody here understand it. Can you come over?" So I heads off across town and when I get there, they've clicked on the program like 50 times, and it just shows the instructions... so I closes all the copies on the desktop... goes WIN_R, types in the program name and drive letter (scan d: ... like it's hard?) and off it went. They honestly had an office full of so called "computer smart" people who had never run a console program before! ... As soon as it didn't produce an OK button they were lost... I'll not repeat that mistake. (Their files were fine, by the way)

    This is the level it's reached. Console programming is viewed as esoteric or "legacy" and nobody wants to deal with it. A programmer, these days, who doesn't use Windowed UIs isn't going to get very far...
    Last edited by CommonTater; 11-23-2011 at 11:54 AM.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Console programs are still useful, if you don't want several hundred lines of boilerplate code just to display a text string and read something from the user.

    Or you're working in an environment which isn't a desktop.

    Or I could go on....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help whit file opening
    By filopelor92 in forum C Programming
    Replies: 1
    Last Post: 05-22-2010, 11:14 AM
  2. Adding uint_64 whit uint_32
    By isato in forum C Programming
    Replies: 4
    Last Post: 06-12-2009, 06:45 PM
  3. Sorting whit MPI
    By isato in forum C Programming
    Replies: 0
    Last Post: 03-03-2009, 10:38 AM
  4. HELP WHIT-What is your name? Hallo _____
    By NewBoy in forum C++ Programming
    Replies: 7
    Last Post: 10-20-2002, 05:06 PM

Tags for this Thread