EncodeJPEGImageTo

#include "BIJPEG.H"

int CALLBACK EncodeJPEGImageTo( INT_PTR     nFile,
WORD        wWidth,
WORD        wHeight,
int                 nColors,
int                 nQuality,
INT_PTR     lUserData,
FILLPROC lpLineFn,
DWORD     dwXRes,
DWORD     dwYRes)

Description

Compresses an image into a JPEG file. The raw image data must be passed to the function through the user defined callback function line by line. The value of nQuality parameter must be in the range of 1 to 100. Increasing the value of the quality, the quality of the saved image will be increased; but the size of the JPEG file will grow.

Parameters

INT_PTR

nFile

Image file handle.

WORD

wWidth

Width of the image in pixels.

WORD

wHeight

Height of the image in pixels.

int

nColors

Color plains. 1 for 8 bit gray scale and 3 for 24 bit image.

int

nQuality

Compression loss ratio.

INT_PTR

lUserData

User defined info. It is passed to the callback function as a third parameter unchanged.

FILLPROC

lpLineFn

Callback function, which will pass the DIB lines.

DWORD

dwXRes

Resolution of image in X direction. Dot per meter.

DWORD

dwYRes

Resolution of image in Y direction. Dot per meter.

Programming notes

The callback function pointed by the lpLineFn parameter must use the Pascal calling convention and must have the following form:

int CALLBACK LineFn(LPSTR lpLineBuff, int nLine, INT_PTR lParam)

LineFn is a placeholder for the application-supplied function name. You can use any other name for this purpose.

Parameters

LPSTR

lpLineBuff

Buffer to put a single line DIB into (of course, without header).

int

nLine

Index of the required line. Line numbers are started from zero.

LONG

lParam

The lUserData parameter passed to the EncodeJPEGImageTo() function. The user can use this parameter freely.

Return values

Returns 0 on success, else error code

JERR_FILE                                                  Write to the file failed.

JERR_MEMORY                                        Not enough memory.

JERR_COMPRESSION                             Error while compressing.

JERR_NOLINEPROC                                lpLineFn is NULL.

JERR_COLORS                                           The DIB is not a 24 bit color or 8 bit grayscale image.

Requirements

Header :     Declared in BiJpeg.h; include BiJpeg.h.

Library :    Use BiJpeg.lib.

DLLs :       BiJpeg.dll.