【问题标题】:FreeImage include in cFreeImage 包含在 c 中
【发布时间】:2013-05-21 22:56:22
【问题描述】:

有没有什么方法可以在我的 c 测试程序中包含 http://freeimage.sourceforge.net/index.html 而无需先安装库?由于某些memset,它无法编译..

这是我的 C 代码。有什么办法让它工作吗?请尝试编译它并告诉我如果它有效怎么做?

#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;
}

【问题讨论】:

    标签: c image compilation compiler-errors freeimage


    【解决方案1】:

    不,你不能。要编译您的源代码,链接器需要该库。

    【讨论】:

    • 或者更具体地说,编译器需要头文件来编译你的 C 代码,或者链接器需要库来链接你的目标文件
    • 你错了。动态链接库将允许做他想做的事。
    • 编译器需要库来更正解析符号并映射库函数的地址。根据您的编译器和目标操作系统,您可以选择动态链接。这又会在系统上加载最新版本的库。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 2020-10-03
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 2019-04-25
    相关资源
    最近更新 更多