Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

handling bitmaps with C++ 1

Status
Not open for further replies.

ieva

Programmer
Nov 8, 2002
3
LV
Hi!

1) How to get separate pixels (RGB values) from bitmap image with C++?
2) How to generate a new bitmap of new calculated pixels?

Thanks,
Ieva
 
Could make a cool encryption program. I am waiting for the
response myself.
 
hi ieva,

try this

hennep

//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender) {
AnsiString as;

Image1->Picture->Bitmap->LoadFromFile( (AnsiString)"c:\\test.bmp" );

// read a pixel
for( int x=0; x<Image1->Picture->Bitmap->Width; x++ ) {
for( int y=0; y<Image1->Picture->Bitmap->Height; y++ ) {
as = &quot;TColor = &quot;;
as += (long)Image1->Picture->Bitmap->Canvas->Pixels[x][y];
Application->MessageBoxA( as.c_str(), &quot;debug&quot;, 0 );
}
}
//write a pixel
for( int x=0; x<Image1->Picture->Bitmap->Width; x++ ) {
for( int y=0; y<Image1->Picture->Bitmap->Height; y++ ) {
Image1->Picture->Bitmap->Canvas->Pixels[x][y] = clRed;
}
}
}
//---------------------------------------------------------------------------
 
And to answer the secon part of you question:

//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender) {
AnsiString as;

Image1->Picture->Bitmap->LoadFromFile( (AnsiString)&quot;c:\\test.bmp&quot; );

Image2->Picture->Bitmap->Width = Image1->Picture->Bitmap->Width;
Image2->Picture->Bitmap->Height = Image1->Picture->Bitmap->Height;
for( int x=0; x<Image1->Picture->Bitmap->Width; x++ ) {
for( int y=0; y<Image1->Picture->Bitmap->Height; y++ ) {
Image2->Picture->Bitmap->Canvas->Pixels[x][y] = Image1->Picture->Bitmap->Canvas->Pixels[x][y] - 100;
}
}

Image2->Picture->Bitmap->SaveToFile( (AnsiString)&quot;c:\\test2.bmp&quot; );
}
//---------------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top