can anyone help me with this code to load a bmp image, change its colour to grey and save it back, with input file parameters being asked from the user. my code uses BMP library called easyBMP. i couldnt load it bt it can be easily downloaded from the net. thank u in advance:)
#include <iostream>
#include "EasyBMP.h"
using namespace std;
int main( int argc, char* argv[] )
{
if( argc != 3 )
{
cout << "Usage: ColorBMPtoGrayscale <input_filename> <output_filename>"
<< endl << endl;
return 1;
}
// declare and read the bitmap
BMP Input;
Input.ReadFromFile( "cartman.bmp" );
// convert each pixel to grayscale using RGB->YUV
for( int j=0 ; j < Input.TellHeight() ; j++)
{
for( int i=0 ; i < Input.TellWidth() ; i++)
{
int Temp = (int) floor( 0.299*Input(i,j)->Red +
0.587*Input(i,j)->Green +
0.114*Input(i,j)->Blue );
ebmpBYTE TempBYTE = (ebmpBYTE) Temp;
Input(i,j)->Red = TempBYTE;
Input(i,j)->Green = TempBYTE;
Input(i,j)->Blue = TempBYTE;
}
}
// Create a grayscale color table if necessary
if( Input.TellBitDepth() < 16 )
{ CreateGrayscaleColorTable( Input ); }
// write the output file
Input.WriteToFile( "out.bmp" );
return 0;
}
cartman.bmp ( 71.26k )
Number of downloads: 22This post has been edited by himusar: 2 Apr, 2008 - 02:32 PM