Error Handling Example

This example program is written for testing error messages. To generate an error message, try creating an image with alpha=1. (In the library, the correct value of alpha is either the number of the last channel or 0, which indicates that there is no alpha channel in the image.)

If you use the default error-handling mode, IPL_ErrModeLeaf, you'll get the error message. If you set IPL_ErrModeSilent mode, then you won't get the message.

You can run this code by using the Java applet on this page or from the command line:
>create -t0 -a1 [-e]
(-a specifies the alpha value; -e sets the error mode to IPL_ErrModeSilent).

The source:

bool handle_error( int alpha, bool silent, int
width=100, int height=100 ) {

    iplSetErrMode( silent ? IPL_ErrModeSilent : IPL_ErrModeLeaf );
    /// create an image with alpha channel
    IplImage* img = iplCreateImageHeader(
        4,                     // 4 channels
        alpha,                 // error: alpha is 1st channel 
                               //     should be 0 or 4 
        IPL_DEPTH_8U,          // data type 
        "RGBA", "RGB",         // color model, channel sequence
        IPL_DATA_ORDER_PIXEL,  // channel arrangement
        IPL_ORIGIN_TL,         // top left orientation
        IPL_ALIGN_DWORD,       // 4 bytes align
        width, height,         // image width and height
        NULL, NULL, NULL, NULL // no ROI, no mask, id, no tile
    );
    if( img ) {
        /// allocate image data with filling 
        iplAllocateImage( img, 1, 128 );
        /// show the image
        if( img->imageData )
        ipView( img, " rgbAlpha", is_modal );
        /// free memory. Function checks if imageData is NULL
        iplDeallocate( img, IPL_IMAGE_ALL );
    }
    return IPL_StsOk == iplGetErrStatus();
}

* Legal Information © 1998-2000, Intel Corporation