Cesar C. Salazar Gonzalez Master


Registrado: 01 Oct 2002Mensajes: 2155Ubicación: San Cristóbal de Las Casas, Chiapas
|
Publicado: Jue 10 Abr, 2008 11:34 am Asunto: |
|
|
Esto funciona solo en Imagenes mapa de bits (bmp)
son dos funciones que te permiten realizar esta operacion, aun que se hacen por separado funciona perfectamente
| Código: | // creas un mpata de bits
Graphics::TBitmap *tbmp = new Graphics::TBitmap();
// le asignas la imagen que quieres convertir
tbmp->Assign(this->Image1->Picture->Bitmap);
Brillo(tbmp,190);Contraste(tbmp,10); // modficas
// y la asignas a un TQRImage
this->QRImage1->Picture->Assign(tbmp); |
y las funciones son las siguientes
| Código: |
//**************************************************************************
// Tratamiento de Imagens Brillo y contraste
//--------------------------------------------------------------------
byte __fastcall IntToByte(int i)
{
if (i>=255) return 255;
if (i<=0) return 0;
return i;
}
//--------------------------------------------------------------------
void __fastcall Brillo(Graphics::TBitmap *Imagen, int Escala)
{
Byte *p0;
int r,g,b,p,x,y;
y=0;
while( y < Imagen->Height)
{
p0 = (Byte*) Imagen->ScanLine[y];
x = 0;
while( x < Imagen->Width)
{
Application->ProcessMessages();
r=p0[x*3];
g=p0[x*3+1];
b=p0[x*3+2];
p0[x*3] =IntToByte(r+((255-r)*Escala) / 255);
p0[x*3+1]=IntToByte(g+((255-g)*Escala) / 255);
p0[x*3+2]=IntToByte(b+((255-b)*Escala) / 255);
x++;
}
y++;
}
}
//--------------------------------------------------------------------
void __fastcall Contraste(Graphics::TBitmap *Imagen, int Escala)
{
Byte *p0;
int rg,gg,bg,r,g,b,x,y;
y=0;
while( y < Imagen->Height )
{
p0 = (Byte*) Imagen->ScanLine[y];
x = 0;
while( x < Imagen->Width)
{
Application->ProcessMessages();
r=p0[x*3];
g=p0[x*3+1];
b=p0[x*3+2];
rg= (abs(127-r)*Escala) / 255;
gg= (abs(127-g)*Escala) / 255;
bg= (abs(127-b)*Escala) / 255;
if(r > 127) r = r+rg; else r =r-rg;
if(g > 127) g = g+gg; else g =g-gg;
if(b > 127) b = b+bg; else b =b-bg;
p0[x*3] =IntToByte(r);
p0[x*3+1] =IntToByte(g);
p0[x*3+2] =IntToByte(b);
x++;
}
y++;
}
}
//---------------------------------------------------------------------------
|
Saludos _________________
 |
|