Advanced save functions

Saving bitmaps using the ...SaveToHandle functions is almost identical to loading bitmap via the ...LoadFromHandle functions. Information about the FreeImageIO and fi_handle can therefore be obtained from the information belonging to these functions.

unsigned

_ReadProc(FIBITMAP *buffer, unsigned s, unsigned c, fi_handle handle) {

return fread(buffer, s, c, (FILE *)handle);

}

unsigned

_WriteProc(FIBITMAP *buffer, unsigned s, unsigned c, fi_handle handle){

return fwrite(buffer, s, c, (FILE *)handle);

}

int

_SeekProc(fi_handle handle, long offset, int origin) {

return fseek((FILE *)handle, offset, origin);

}

long

_TellProc(fi_handle handle) {

return ftell((FILE *)handle);

}

FreeImageIO io;

io.read_proc = _ReadProc;

io.write_proc = _WriteProc;

io.seek_proc = _SeekProc;

io.tell_proc = _TellProc;


FILE *file = fopen("test.bmp", "rb");

FIBITMAP *dib = FreeImage_LoadBMPFromHandle(&io, (fi_handle)file);


fclose(file);

if (dib != NULL) {

file = fopen("saved.bmp", "wb");

FreeImage_SavePNGToHandle(dib, &io, (fi_handle)file);
fclose(file);
}

FreeImage_Free(dib);

Subsections

FreeImage_SaveBMPToHandle

bool FreeImage_SaveBMPToHandle(FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags = BMP_DEFAULT);

Saves the FreeImage DIB to a Windows Bitmap file. The BMP file is always saved in the Windows format. No compression is used.

FreeImage_SaveJPEGToHandle

bool FreeImage_SaveJPEGToHandle(FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags = JPEG_DEFAULT);

Saves the FreeImage DIB to a JPEG file. Only 24-bit bitmaps can be saved as JPEG. Bitmaps in bit depths will have to be converted.

FreeImage_SavePNGToHandle

bool FreeImage_SavePNGToHandle(FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags = PNG_DEFAULT);

Saves the FreeImage DIB to a PNG file.

FreeImage_SavePNMToHandle

bool FreeImage_SavePNMToHandle(FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags = PNM_DEFAULT);

Saves the FreeImage DIB to a PNM file. PNM is a descriptive name for a collection of ASCII based bitmap types: PBM, PGM and PPM. If the bitmap has a bitdepth of 1, the file is saved as a PBM file. If the bitmap has a bitdepth of 8, the file is saved as a PGM file. If the bitmap has a bitdepth of 24, the file is saved as a PPM file. Other bitdepths are not supported.

FreeImage_SaveTIFFToHandle

bool FreeImage_SaveTIFFToHandle(FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags = TIFF_DEFAULT);

Saves the FreeImage DIB to a TIFF file.

FreeImage_SaveWBMPToHandle

bool FreeImage_SaveWBMPToHandle(FIBITMAP *dib, FreeImageIO *io, fi_handle handle, int flags = WBMP_DEFAULT);

Saves the FreeImage DIB to a WBMP file.