当前位置: 首页>>代码示例>>C++>>正文


C++ BitMap::getWidth方法代码示例

本文整理汇总了C++中BitMap::getWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ BitMap::getWidth方法的具体用法?C++ BitMap::getWidth怎么用?C++ BitMap::getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitMap的用法示例。


在下文中一共展示了BitMap::getWidth方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: savePicAsHeightMap

void savePicAsHeightMap( std::string const& infile, std::string const& outfile ) {

	ImageIO::init();

	BitMap*	in	= ImageIO::load( infile );
	BitMap* out	= new BitMap( in->getWidth(), in->getHeight() );

	for( int j=0; j<in->getHeight(); j++ ) {
		for( int i=0; i<in->getWidth(); i++ ) {
			unsigned int col = in->get( i, j );
			int r = ( col >> 16 ) & 0xff;
			int g = ( col >> 8 ) & 0xff;
			int b = col & 0xff;
			int v = (int)( (double)r * 0.2125 + (double)g * 0.7154 + (double)b * 0.0721 ) & 0xff;
			out->set( i, j, ( 0xff << 24 ) | ( v << 16 ) | ( v << 8 ) | v );
		}
	}

	ImageIO::save( outfile, *out );

	delete out;
	delete in;
}
开发者ID:mgnauck,项目名称:miko-raytracer,代码行数:23,代码来源:_trash.cpp

示例2: save

bool BMP::save( std::string const& filename, BitMap const& map ) {

	FILE*	f	= fopen( filename.c_str(), "wb" );

	assert( f );

	int	width	= map.getWidth();
	int	height	= map.getHeight();

	// bitmap file header
	unsigned short	bfType			= 0x4D42;								// "BM"
	unsigned int	bfSize			= 54 + width * height * 3;
	unsigned short	bfReserved1		= 0;
	unsigned short	bfReserved2		= 0;
	unsigned int	bfOffbits		= 54;
	
	fwrite( &bfType, 2, 1, f );
	fwrite( &bfSize, 4, 1, f );
	fwrite( &bfReserved1, 2, 1, f );
	fwrite( &bfReserved2, 2, 1, f );
	fwrite( &bfOffbits, 4, 1, f );

	// bitmap info header
    unsigned int	biSize			= 40;							// bmih size
    int				biWidth			= width;
    int				biHeight		= height;
    unsigned short	biPlanes		= 1;
    unsigned short	biBitCount		= 24;							// RGB
    unsigned int	biCompression	= 0;							// type: RGB
    unsigned int	biSizeImage		= width * height * 3;
    int				biXPelsPerMeter	= 2925;
    int				biYPelsPerMeter	= 2925;
    unsigned int	biClrUsed		= 0;
    unsigned int	biClrImportant	= 0;

	fwrite( &biSize, 4, 1, f );
	fwrite( &biWidth, 4, 1, f );
	fwrite( &biHeight, 4, 1, f );
	fwrite( &biPlanes, 2, 1, f );
	fwrite( &biBitCount, 2, 1, f );
	fwrite( &biCompression, 4, 1, f );
	fwrite( &biSizeImage, 4, 1, f );
	fwrite( &biXPelsPerMeter, 4, 1, f );
	fwrite( &biYPelsPerMeter, 4, 1, f );
	fwrite( &biClrUsed, 4, 1, f );
	fwrite( &biClrImportant, 4, 1, f );

	// write data
	for( int j=0; j<height; j++ ) {

		for( int i=0; i<width; i++ ) {

			unsigned int	c	= map.get( i, height - j - 1 );

			unsigned char	b	= ( c >> 16 ) & 0xff;
			unsigned char	g	= ( c >> 8 ) & 0xff;
			unsigned char	r	= c & 0xff;

			fwrite( &b, 1, 1, f );
			fwrite( &g, 1, 1, f );
			fwrite( &r, 1, 1, f );
		}
	}

	fclose( f );

	return true;
}
开发者ID:mgnauck,项目名称:miko-raytracer,代码行数:68,代码来源:BMP.cpp


注:本文中的BitMap::getWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。