Specifications
Image Creation and Access
4-51
4
• The dimensions of the converted IplImage should be greater than or
equal to that of the DIB image. When the converted image is larger
than the DIB image, the origins of
IplImage and the DIB image are
made coincident for the purposes of copying.
• When converting a DIB RGBA image, the destination
IplImage
should also contain an alpha channel.
Example 4-9 Converting a DIB Image Into an IplImage
int example48( void ) {
BITMAPINFO *dib; // pointer to bitmap
RGBQUAD *rgb; // pointer to bitmap colors
unsigned char *data; // pointer to bitmap data
BITMAPINFOHEADER *dibh; // header beginning
IplImage *img = NULL;
int i;
__try {
int size = HEIGHT * ((WIDTH+3) & ~3);
// allocate memory for bitmap
dib = malloc(sizeof(BITMAPINFOHEADER)
+ sizeof(RGBQUAD)*256 + size );
if( NULL == dib ) return 0;
// define corresponedt pointers
dibh = (BITMAPINFOHEADER*)dib;
rgb=(RGBQUAD*)((char*)dib + sizeof(BITMAPINFOHEADER));
data = (unsigned char*)((char*)rgb +
sizeof(RGBQUAD)*256);
// define bitmap
dibh->biSize = sizeof(BITMAPINFOHEADER);
dibh->biWidth = WIDTH;
dibh->biHeight = HEIGHT;
dibh->biPlanes = 1;
dibh->biBitCount = 8;
continued
☞