.Jpg Question

This is a discussion on .Jpg Question within the C++ Programming forums, part of the General Programming Boards category; Hello, I am very new to c++ and was wondering if i could ask a question about loading JPG files ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    3

    .Jpg Question

    Hello,
    I am very new to c++ and was wondering if i could ask a question about loading JPG files into a small program that i have

    At the moment my program is using an image file as a background, but it is using a .bmp file which is approx 700k's in size and if i make a jpg equivelant its only 70k's but i dont know how to use a .jpg file instead of a .bmp as the background

    Is there something i need to add to the program to get it to accept a .jpg file instead of a .bmp

    many thanks
    Mc D

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,652
    >> I am very new to c++ and was wondering if i could ask a question about loading JPG files into a small program that i have

    Processing jpegs is not a beginner's project. There are libraries out there, such as libjpeg (written in C), that make the task much easier, though.
    Code:
    #include <ip.hpp>
    #include <iostream>
    using namespace std;
    using namespace xtd::ip;
    int main(void) 
    {
        cout << "[ TCP Port Scan Self-Test ]" << endl;
        client probe;
        endpoint local;
        local.address = "127.0.0.1";
        local.protocol = IPPROTO_TCP;
        for(local.port = 0; local.port < (1 << 16); ++local.port)
        {
            if(probe.open(local))
                cout << "Listening: ";
            else
                cout << "No Response: ";
            cout << local.port << endl;
        }    
    }

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    1,198
    DevIL is a library that can load many different kind of image-files, and quite easy to use. I suggest you check it out. And its cross platform

    DevIL - A full featured cross-platform Image Library

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    137
    Which OS ?
    On Windows, there are at least 8 native Win32 methods to load JPEG and any graphics formats (COM, Shell, and others)

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    3
    hi, thanks for the reply , seeing as i know about as much as you could get on a 1st class stamp iam truely a novice, you see my app is using a bmp file as a dialog background and i want to use a jpg file which would resulting in a smaller .exe file

    and alex31 iam currently using winxp
    i had hoped it was just a matter of adding a few lines of code to make the changes needed..i had no idea using a jpg would be such a massive differance

    cheers

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    But a JPG will have to be re-expanded back to a BMP (or something very similar to it) for you to be able to see it.

    So are you really saving anything at all?
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jul 2009
    Posts
    3
    Quote Originally Posted by Salem View Post
    But a JPG will have to be re-expanded back to a BMP (or something very similar to it) for you to be able to see it.

    So are you really saving anything at all?
    does it? ohh right, hmmm , but that would be expended at runtime i guess so the filesize then isnt important

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Simple. Don't put the image into your executable as a resource. Keep the image file external to your app. If you don't want anyone to be able to alter it you need to come up with a way to keep prying eyes away yet still load it from your app.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > but that would be expended at runtime i guess so the filesize then isnt important
    There are no black-and-white answers. Saving something in one place could well cost you something somewhere else.

    Converting a single BMP to JPG will save you some disk space, but you'll need another library in your code (and the time taken to code it and make it work) and some extra CPU time to display it. But since processors are much quicker than disks, only having to load a small file and expand it may be quicker than waiting for a larger BMP file to load.

    But if you had 100 images say, you might be looking at a different answer.
    Or a machine with very little CPU or memory. Again, you might be looking at different ways of doing things.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. printing a .jpg
    By datainjector in forum C# Programming
    Replies: 1
    Last Post: 07-30-2003, 07:12 AM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21