Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,220 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 978 people online right now. Registration is fast and FREE... Join Now!




BMP images

 
Reply to this topicStart new topic

BMP images, Reading, editing and saving back BMP images

himusar
post 2 Apr, 2008 - 02:26 PM
Post #1


New D.I.C Head

*
Joined: 20 Nov, 2007
Posts: 0


My Contributions


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;
}
Attached File  cartman.bmp ( 71.26k ) Number of downloads: 22


This post has been edited by himusar: 2 Apr, 2008 - 02:32 PM
User is offlineProfile CardPM

Go to the top of the page

capty99
post 2 Apr, 2008 - 02:30 PM
Post #2


the real kya

Group Icon
Joined: 26 Apr, 2001
Posts: 9,128



Thanked 15 times

Dream Kudos: 550
My Contributions


this is the introduce yourself forum.
you will not find help here.

welcome though.
User is online!Profile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 08:49PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month