domingo, 11 de septiembre de 2011

Manipulacion de pixeles en una imagen bmp


En este programa aprendimos como manejar la matriz de pixeles usando la mascara para el corrimiento de
los bits y asi poder cambiar el color de la imagen ya sea rojo, verde o azul. Tambien utilizamos la matriz
de pixeles para cambiar la posicion de la imagen. Abajo esta el codigo.


void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{

        TColor color;

        for(int y = 0; y < Image1->Height; y++)
        {
           for(int x = 0; x < Image1->Width; x++)
           {
              color = Image1->Canvas->Pixels[x][y];
              color = color & 255;

              Image2->Canvas->Pixels[x][y] = color;
           }
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
        TColor color;
        int mascara = 255;

        mascara = mascara << 8;

        for(int y = 0; y < Image1->Height; y++)
        {
           for(int x = 0; x < Image1->Width; x++)
           {
              color = Image1->Canvas->Pixels[x][y];
              color = color + mascara;

              Image2->Canvas->Pixels[x][y] = color;
           }
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
        TColor color;
        int mascara = 255;

        mascara = mascara << 16;

        for(int y = 0; y < Image1->Height; y++)
        {
           for(int x = 0; x < Image1->Width; x++)
           {
              color = Image1->Canvas->Pixels[x][y];
              color = color + mascara;

              Image2->Canvas->Pixels[x][y] = color;
           }
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
        //Image3->Picture->LoadFromFile("santos laguna.bmp");
        //Image3->Height = Image2-> Width - 3;
        //Image3->Width = Image2-> Height - 3;
        TColor color;

        for(int x = 0; x < Image1->Width; x++)
        {
           for(int y = 0; y < Image1->Height; y++)
           {
             color = Image1->Canvas->Pixels[x][y];
             Image3->Canvas->Pixels[Image1->Width - x][y] = color;
           }
        }


}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
        TColor color;

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

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
        TColor color;

        for(int x = 0; x < Image1->Width; x++)
        {
           for(int y = 0; y < Image1->Height; y++)
           {
             color = Image1->Canvas->Pixels[x][y];
             Image3->Canvas->Pixels[Image1->Width - x][Image1->Height - y] = color;
           }
        }
}
//---------------------------------------------------------------------------

No hay comentarios:

Publicar un comentario