本文整理汇总了C++中BMP::SetColor方法的典型用法代码示例。如果您正苦于以下问题:C++ BMP::SetColor方法的具体用法?C++ BMP::SetColor怎么用?C++ BMP::SetColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BMP
的用法示例。
在下文中一共展示了BMP::SetColor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BMP
// same as above, but highlights a range of depths in red,
// and, colors all depths outside that range black in refImage
// highlight_low and high are values in [1,100]
BMP * CImage::toHighlightedBmp(int highlight_low, int highlight_high, BMP * refBmp)
{
// scale range to be highlighted to [0,255]
highlight_low = ((float) highlight_low) * 255.0/100.0 - 2.55;
highlight_high = ((float) highlight_high) * 255.0/100.0;
BMP * bmp = new BMP();
bmp->SetSize(m_width, m_height);
// for smaller output file size
bmp->SetBitDepth(8);
// 8-bit bitmaps need a color table
CreateGrayscaleColorTable(*bmp);
// add red to the color table
RGBApixel highlightColor;
highlightColor.Red = 255;
highlightColor.Green = 0;
highlightColor.Blue = 0;
highlightColor.Alpha = 0;
bmp->SetColor(highlight_low, highlightColor);
// copy pixels to bmp
for (int col = 0; col < m_width; col++)
{
for (int row = 0; row < m_height; row++)
{
float pixel = getValue(row, col, 0);
if (highlight_low <= pixel && pixel <= highlight_high)
{
(* bmp)(col, row)->Red = 255;
(* bmp)(col, row)->Green = 0;
(* bmp)(col, row)->Blue = 0;
}
else
{
// Output is grayscale, so R, G, and B components are equal.
// ScaleAndDisplayDisparityValues() et. al. in stereo.cpp have already
// scaled all float pixel values to [0, 255].
ebmpBYTE byteVal = (ebmpBYTE) pixel;
(* bmp)(col, row)->Red = byteVal;
(* bmp)(col, row)->Green = byteVal;
(* bmp)(col, row)->Blue = byteVal;
// color non-highlighted areas black in refBmp
(* refBmp)(col, row)->Red = 0;
(* refBmp)(col, row)->Green = 0;
(* refBmp)(col, row)->Blue = 0;
}
}
}
return bmp;
}
示例2: ExportBMP
bool ExportBMP( const _TImg_t & in_indexed,
const std::string & filepath )
{
//shorten this static constant
typedef utils::do_exponent_of_2_<_TImg_t::pixel_t::mypixeltrait_t::BITS_PER_PIXEL> NbColorsPP_t;
BMP output;
output.SetBitDepth(_TImg_t::pixel_t::GetBitsPerPixel());
if( in_indexed.getNbColors() != NbColorsPP_t::value )
{
#ifdef _DEBUG
assert(false);
#endif
throw std::runtime_error( "ERROR: The tiled image to write to a bitmap image file has an invalid amount of color in its palette!" );
}
//copy palette
for( int i = 0; i < NbColorsPP_t::value; ++i )
output.SetColor( i, colorRGB24ToRGBApixel( in_indexed.getPalette()[i] ) );
//Copy image
output.SetSize( in_indexed.getNbPixelWidth(), in_indexed.getNbPixelHeight() );
for( int i = 0; i < output.TellWidth(); ++i )
{
for( int j = 0; j < output.TellHeight(); ++j )
{
auto & refpixel = in_indexed.getPixel( i, j );
uint8_t temp = static_cast<uint8_t>( refpixel.getWholePixelData() );
output.SetPixel( i,j, colorRGB24ToRGBApixel( in_indexed.getPalette()[temp] ) ); //We need to input the color directly thnaks to EasyBMP
}
}
bool bsuccess = false;
try
{
bsuccess = output.WriteToFile( filepath.c_str() );
}
catch( std::exception e )
{
cerr << "<!>- Error outputing image : " << filepath <<"\n"
<< " Exception details : \n"
<< " " <<e.what() <<"\n";
assert(false);
bsuccess = false;
}
return bsuccess;
}