본문 바로가기

프로그래밍/Delphi

xnView-GFL_SDK : 메모리를 이용한 데이터 복사(gflSaveBitmapIntoMemory) 참고자료

C를 이용한 방법
GFL_ERROR init = gflLibraryInit();
    if (GFL_NO_ERROR != init) {
      printf("error: %d\n", init);
      return;
    }
    gflEnableLZW(GFL_TRUE);

    // load jpeg
    GFL_BITMAP *thebitmap = NULL;
    GFL_LOAD_PARAMS lp1;
    gflGetDefaultLoadParams(&lp1);
    lp1.FormatIndex = -1;
    GFL_ERROR e1 = gflLoadBitmap("dsc04034.jpg", &thebitmap, &lp1, NULL);
    if (GFL_NO_ERROR != e1) {
        printf("error: %d\n", e1);
    } else {
        int tiff = gflGetFormatIndexByName("tiff");

        unsigned char* data;
        unsigned long length;
        GFL_SAVE_PARAMS sp1;
        gflGetDefaultSaveParams(&sp1);
        sp1.FormatIndex = tiff;
        sp1.Compression = GFL_LZW;

        printf("saving to mem\n");
        e1 = gflSaveBitmapIntoMemory(&data, &length, thebitmap, &sp1);
        if (GFL_NO_ERROR == e1) {
            printf("saved %d bytes\n", length);
            gflMemoryFree(data);
            printf("freed\n");
        } else {
            printf("error: %d\n", e1);
        }

        gflGetDefaultSaveParams(&sp1);
        sp1.FormatIndex = tiff;
        sp1.Compression = GFL_LZW;
        printf("saving to file\n");
        e1 = gflSaveBitmap("dsc04034.tiff", thebitmap, &sp1);
        if (GFL_NO_ERROR == e1) {
            printf("saved\n");
        } else {
            printf("error: %d\n", e1);
        }        
        gflFreeBitmap(thebitmap);
}

gflLibraryExit();