سؤال

Is there any way to include http://freeimage.sourceforge.net/index.html in my c test program without first installing the library? It fails to compile because of some memset..

Here is my C code. Is there any way to make it work? Please try compiling it and tell me how to do it if it works?

#define NAZIV_DATOTEKE 50
#include <stdio.h>
#include "FreeImage.h"


void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message);
FIBITMAP* GenericLoader(const char* lpszPathName, int flag);

int main(){
    FreeImage_Initialise();
    FIBITMAP *dib, *ptr;
    char ulaz_slika[NAZIV_DATOTEKE] = "bmp_24.bmp";
    char izlaz_slika[NAZIV_DATOTEKE] = "free.bmp";  //podrazumevana vrednost

    dib = GenericLoader(ulaz_slika, 0);
    //slika = FreeImage_Load(FIF_BMP, "bmp_24.bmp", BMP_DEFAULT);
    FreeImage_SetOutputMessage(FreeImageErrorHandler);
    if (dib) {
        printf("Ucitan \"%s\".\n", ulaz_slika);
    }

    FREE_IMAGE_FORMAT fif = FreeImage_GetFileType(ulaz_slika, 0);
    if ((fif != FIF_BMP) && (fif != FIF_ICO) && (fif != FIF_JPEG) && (fif != FIF_PNG) && (fif != FIF_TIFF)){
        printf("Format slike nije podrzan.\n");
        return 1;
    }


    ptr = FreeImage_ConvertTo24Bits(dib);
    FreeImage_SetOutputMessage(FreeImageErrorHandler);
    FreeImage_Unload(dib);
    FreeImage_SetOutputMessage(FreeImageErrorHandler);
    dib = ptr;
    if (dib) {
        printf("Konvertovan u RGB.\n");
    }


    const char *slika = (const char*)FreeImage_GetBits(dib);


    if (FreeImage_Save(fif, dib, izlaz_slika, BMP_DEFAULT)) {
        printf("Snimljen \"%s\".\n", izlaz_slika);
    }


    if (dib) {
        FreeImage_Unload(dib);
    }
    FreeImage_DeInitialise();
    return 0;
}

void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message){
    printf("\n*** ");
    if(fif != FIF_UNKNOWN) {
        if (FreeImage_GetFormatFromFIF(fif))
            printf("%s Format\n", FreeImage_GetFormatFromFIF(fif));
    }
    printf(message);
    printf(" ***\n");
}

FIBITMAP* GenericLoader(const char* lpszPathName, int flag) {
    FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
    // check the file signature and deduce its format
    // (the second argument is currently not used by FreeImage)
    fif = FreeImage_GetFileType(lpszPathName, 0);
    if(fif == FIF_UNKNOWN) {
        // no signature ?
        // try to guess the file format from the file extension
    fif = FreeImage_GetFIFFromFilename(lpszPathName);
    }
    // check that the plugin has reading capabilities ...
    if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
        // ok, let's load the file
        FIBITMAP *dib = FreeImage_Load(fif, lpszPathName, flag);
        // unless a bad file format, we are done !
        return dib;
    }
    return NULL;
}
هل كانت مفيدة؟

المحلول

No you cannot. To compile your source, the linker needs the library.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top