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


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

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


在下文中一共展示了BitMap::set方法的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: load

BitMap* BMP::load( std::string const& filename ) {

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

	assert( f );

	// bitmap file header
	unsigned short	bfType;
	unsigned int	bfSize;
	unsigned short	bfReserved1;
	unsigned short	bfReserved2;
	unsigned int	bfOffbits;

	fread( &bfType, 2, 1, f );
	fread( &bfSize, 4, 1, f );
	fread( &bfReserved1, 2, 1, f );
	fread( &bfReserved2, 2, 1, f );
	fread( &bfOffbits, 4, 1, f );

	// bitmap info header
    unsigned int	biSize;
    int				biWidth;
    int				biHeight;
    unsigned short	biPlanes;
    unsigned short	biBitCount;
    unsigned int	biCompression;
    unsigned int	biSizeImage;
    int				biXPelsPerMeter;
    int				biYPelsPerMeter;
    unsigned int	biClrUsed;
    unsigned int	biClrImportant;

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

	BitMap* m = new BitMap( biWidth, biHeight );

	// read data
	for( int j=0; j<biHeight; j++ ) {

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

			unsigned char	a, r, g, b;

			fread( &b, 1, 1, f );
			fread( &g, 1, 1, f );
			fread( &r, 1, 1, f );

			if( biBitCount == 32 )
				fread( &a, 1, 1, f );	
			else if( biBitCount == 24 )
				a = 0xff;

			m->set( i, biHeight - j - 1, ( a << 24 ) | ( b << 16 ) | ( g << 8 ) | r );
		}
	}

	fclose( f );

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


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