|
|
发表于 2006-10-13 23:41:00
|
显示全部楼层
Re:请问高手们,DX用16位位图难道只能用24位位图转换吗?
我还在搞调色板捏。16位以上的图片用的不多,以下仅供楼主参考,说错了不管^_^,我是菜鸟。
24位的位图硬转成16位,肯定会丢失信息,如果此时导入16位的图是会显示不正常。
如果屏幕每个象素是占16位(2字节)的,24位的是可以直接读取的吧。
这是Windows游戏编程大师中读取16位位图的函数,读24位的位图照样正常。
int Load_Image_Bitmap16(BITMAP_IMAGE_PTR image, // bitmap image to load with data
BITMAP_FILE_PTR bitmap, // bitmap to scan image data from
int cx,int cy, // cell or absolute pos. to scan image from
int mode) // if 0 then cx,cy is cell position, else
// cx,cy are absolute coords
{
// this function extracts a 16-bit bitmap out of a 16-bit bitmap file
// is this a valid bitmap
if (!image)
return(0);
// must be a 16bit bitmap
USHORT *source_ptr, // working pointers
*dest_ptr;
// test the mode of extraction, cell based or absolute
if (mode==BITMAP_EXTRACT_MODE_CELL)
{
// re-compute x,y
cx = cx*(image->width+1) + 1;
cy = cy*(image->height+1) + 1;
} // end if
// extract bitmap data
source_ptr = (USHORT *)bitmap->buffer +
cy*bitmap->bitmapinfoheader.biWidth+cx;
// assign a pointer to the bimap image
dest_ptr = (USHORT *)image->buffer;
int bytes_per_line = image->width*2;
// iterate thru each scanline and copy bitmap
for (int index_y=0; index_y < image->height; index_y++)
{
// copy next line of data to destination
memcpy(dest_ptr, source_ptr,bytes_per_line);
// advance pointers
dest_ptr += image->width;
source_ptr += bitmap->bitmapinfoheader.biWidth;
} // end for index_y
// set state to loaded
image->attr |= BITMAP_ATTR_LOADED;
// return success
return(1);
} // end Load_Image_Bitmap16 |
|