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