Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Newbie C++ problem

Options
  • 18-04-2006 2:05pm
    #1
    Registered Users Posts: 1,997 ✭✭✭


    I'm trying to figure out how to convert a bmp into a png. My searching brought me to the CxImage class. Problem is that I haven't a clue how to use it in my code.

    The site is here which is supposed to tell me everything. Unfortunatly I'm new at all this and am having trouble following it.

    It says that I've to go to the main header file ximcfg.h to find switches to enable/disable the different graphic formats that it supports. Now I can't find this header file. The closest is ximacfg.h. This contains a heap of #define's. Do I delete/comment out the one's I don't need to use?

    Moving onto the next step is where it really confuses me. I really haven't a clue what files to add and what I don't need to add. I'm guessing that I don't need them all as I'm just using a the png format - but what I add and don't need - I really haven't a clue.

    And to add more confusion I'm not sure about the project settings I've to change to use CxImage in my project.

    All this to add in
    CxImage  image;
    // bmp -> jpg
    image.Load("image.bmp", CXIMAGE_FORMAT_BMP);
    if (image.IsValid()){
        if(!image.IsGrayScale()) image.IncreaseBpp(24);
        image.SetJpegQuality(99);
        image.Save("image.jpg",CXIMAGE_FORMAT_JPG);
    }
    
    well except changing the format to png instead of jpg

    Is all this hassle normal for adding classes to c++ projects? Would I be better off using a different library? (can anyone suggest one)

    I'm using visual studio 2005 - and can't get started on this at all. Any help would be greatly appreciated.


Comments

  • Registered Users Posts: 919 ✭✭✭timeout


    I know this might sound silly but could you not just rename the file(from within the program). EG. image.bmp to image.png

    You more then likly need it changed internally or something but just a suggestion.


  • Registered Users Posts: 1,997 ✭✭✭The_Bullman


    timeout wrote:
    I know this might sound silly but could you not just rename the file(from within the program). EG. image.bmp to image.png

    I don't think I can do that. PNG format compresses the bitmap. I don't think changing the exension will do that for me


  • Registered Users Posts: 2,320 ✭✭✭Q_Ball


    It says that I've to go to the main header file ximcfg.h to find switches to enable/disable the different graphic formats that it supports. Now I can't find this header file. The closest is ximacfg.h. This contains a heap of #define's. Do I delete/comment out the one's I don't need to use?

    It only says to do this to reduce the size of the library. The library size matters when compiling the project, the bgger the library the longer the compile time. There's no need to do this when debugging but it might be an idea to do it before release.
    Moving onto the next step is where it really confuses me. I really haven't a clue what files to add and what I don't need to add. I'm guessing that I don't need them all as I'm just using a the png format - but what I add and don't need - I really haven't a clue.

    When you open up the cximage.dsw, the easiest thing to do is compile the entire solution. This will result in the following files being created

    * CxImage : cximage.lib - static library
    * CxImageCrtDll : cximagecrt.dll - DLL not using mfc
    * CxImageMfcDll : cximage.dll - DLL using mfc
    * Demo : demo.exe - program linked with cximage.lib and the C libraries
    * DemoDll : demodll.exe - program linked with cximagecrt.dll
    * j2k,jasper,jbig,jpeg,png,tiff,zlib : static C libraries

    cximage.lib, the png library are the only ones you seem to need*. If you are using visual studio, change the settings according to the next part of that site, but only include cximage.lib, png.lib. the ..\cximage and all the ..\* chages refer to the path to those folders. you might have to change it to something like C:\stuff\cximage etc.
    CxImage  image;
    // bmp -> jpg
    image.Load("image.bmp", CXIMAGE_FORMAT_BMP);
    if (image.IsValid()){
        if(!image.IsGrayScale()) image.IncreaseBpp(24);
        image.SetJpegQuality(99);
        image.Save("image.jpg",CXIMAGE_FORMAT_JPG);
    }
    
    well except changing the format to png instead of jpg

    i'm sorry if this sounds simplistic but i like to break things up like this when i'm in your situation.

    image.Load() takes in the name of a file. CXIMAGE_FORMAT_BMP defines the image as a bitmap.

    if(!image.IsGrayScale()) image.IncreaseBpp(24); checks to see if the image is a grayscale image. if it is, the IncreaseBpp(24) changes it from a grayscale to a 24bit image (this may be for jpegs only)

    image.SetJpegQuality() sets the quality of the jpeg image that the bmp is to be converted into. this isnt needed for your png image but i would check to see if there is a SetPngQuality() method in the library.

    image.Save() saves the image as the first parameter (image.jpg) in the format specified by the second parameter (CXIMAGE_FORMAT_JPG). This will have to be changed to save it as a png format, the flag being possibly CXIMAGE_FORMAT_PNG.

    what i would do to test is leave out the setJpegQuality() call and change the save() to image.png and CXIMAGE_FORMAT_PNG and see what happens.
    Is all this hassle normal for adding classes to c++ projects?

    in my experience, yes. But i havent a heck of a lot of experience in C++ :p

    *by only including these two libraries, bmp might not be supported. since you've compiled all the cximage libraries, there's no harm in including them all and at a later date (i.e. when the project is working), remove the unnecessary ones.


  • Registered Users Posts: 1,997 ✭✭✭The_Bullman


    I'll start at the start
    Q_Ball wrote:
    When you open up the cximage.dsw, the easiest thing to do is compile the entire solution. This will result in the following files being created

    * CxImage : cximage.lib - static library
    * CxImageCrtDll : cximagecrt.dll - DLL not using mfc
    * CxImageMfcDll : cximage.dll - DLL using mfc
    * Demo : demo.exe - program linked with cximage.lib and the C libraries
    * DemoDll : demodll.exe - program linked with cximagecrt.dll
    * j2k,jasper,jbig,jpeg,png,tiff,zlib : static C libraries

    Problem - I can't get this far

    cximage.lib, demo.exe, demodll.exe aren't created when I compile. I haven't a clue about the static C libraries.

    On to the properties
    Project Settings
     |- C/C++
     |   |- Code Generation
     |   |   |- Use run-time library : Multithreaded DLL (must be the same for 
     |   |   |  all the linked libraries)
     |   |   |- Struct member alignment : must be the same for all the linked 
     |   |   |  libraries
     |   |- Precompiled headers : not using precompiled headers
     |   |- Preprocessor
     |       |- Additional Include Directories:  ..\cximage
     |- Link
        |- General
            |- Object/library modules: ../png/Debug/png.lib 
                                       ../jpeg/Debug/jpeg.lib 
                                       ../zlib/Debug/zlib.lib 
                                       ../tiff/Debug/tiff.lib 
                                        ../cximage/Debug/cximage.lib  ...
    

    I've set the run time library
    left the struct member alignment to default
    precompiled headers is set
    preprocessor-> wasn't given this option in this area. I changed it instead in the general section.

    I don't have a link section so I'm not sure where to change those settings

    here's a screenshot of my properties window


  • Registered Users Posts: 2,082 ✭✭✭Tobias Greeshman


    Here's how I got it working:

    Open the CxImageLib workspace file (I used VS 2003), and converted it to Release Build and rebuilt the entire solution.

    Copy the following:
    cximage.lib (cximage/cximage/release) -> Program Files\VS2003\VC\Lib\
    cximage.dll (cximage/bin/release) -> Windows\System32\

    Copy all of the header files in the cximage\cximage folder into a folder called cximage and copy this folder to Program Files\VS2003\VC\Include\

    Then in code, to reference code just use
    #include <cximage\ximage.h>
    

    BTW: Code compiles but JPG or PNG files generated won't load, so generating PNG files are going to need more than just a call to the Save function.


  • Advertisement
  • Registered Users Posts: 1,997 ✭✭✭The_Bullman


    silas wrote:
    Here's how I got it working:

    Open the CxImageLib workspace file (I used VS 2003), and converted it to Release Build and rebuilt the entire solution.

    I opened CxImgLib.dsw (can't find CxImageLib)

    Clicked on the build menu -> configuration manager -> set active solution configuration to release and closed

    Clicked Build

    ... and I got errors. The .dll files were not created.

    I also tried different combinations of batch builds on CxImgLib.dsw, again with no joy :(
    BTW: Code compiles but JPG or PNG files generated won't load, so generating PNG files are going to need more than just a call to the Save function.

    So is it worth my while wasting anymore time on this library at all? Would I be better off using a differnt library. Can anyone recommend one?

    Thanks for your help anyway


  • Registered Users Posts: 131 ✭✭theexis


    If you're on Windows (which I assume you are) GDI+ will do this kind of work for you. Take a look at the Save method on the Image object (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/GDIPlusReference/Classes/Image.asp)


Advertisement