 |
Club Builder Foro de C++Builder en español
|
| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
tyloya Master

Registrado: 20 Ago 2002Mensajes: 175
|
Publicado: Lun 02 Sep, 2002 4:02 pm Asunto: Escala de grises |
|
|
Sigo sin dar con la manera de conseguir mostrar una escala de grises.
Me dijeron que para hacer una matriz en un form usara como componente un TPanel o TPaintBox.
¿Hay que acceder a la paleta de colores de windows, cómo lo hago......?
Lo que pretendo es mostrar escalas de grises pasando desde el blanco al negro en cada uno de los cuadros de la matriz y NO SÉ CÓMO HACERLO!!
Por favor, alguien que me intente ayudar.
Gracias |
|
| Volver arriba |
|
 |
Alfredo Invitado
|
Publicado: Lun 02 Sep, 2002 5:15 pm Asunto: Degradee |
|
|
Hola, Prueba esto para actuar sobre un Form o cualquier objeto con acceso a la propiedad Canvas.
Ponlo en cualquier evento, preferible onPaint
float Step, stepr,stepg, stepb;
TColor cInicial=clWhite;
TColor cFinal=clBlack;
TRect BandRect;
int Orientacion=2;//1=Vertical
//2=Horiontal
int r1=GetRValue((unsigned long)cInicial);
int g1=GetGValue((unsigned long)cInicial);
int b1=GetBValue((unsigned long)cInicial);
int r2=GetRValue((unsigned long)cFinal);
int g2=GetGValue((unsigned long)cFinal);
int b2=GetBValue((unsigned long)cFinal);
int r3,g3,b3;
stepr=(float)(r1-r2)/256;
stepg=(float)(g1-g2)/256;
stepb=(float)(b1-b2)/256;
if (Orientamento==1)
{
Step=(float)Height/256;
}
else
{
Step=(float)Width/256;
}
for(int i=0;i<256;i++)
{
if (Orientacion==1)
{
BandRect.Left=0;
BandRect.Top=(int)(i*Step);
BandRect.Right=Width+1;
BandRect.Bottom=(int)((i+1)*Step);
}
else
{
BandRect.Left=(int)(i*Step);
BandRect.Top=0;
BandRect.Right=(int)((i+1)*Step);
BandRect.Bottom=Height+1;
}
if ((r1<r2))
{
r3=r1+stepr*i;
}
else
{
r3=r1-stepr*i;
}
if (g1<g2)
{
g3=g1+stepg*i;
}
else
{
g3=g1-stepg*i;
}
if (b1<b2)
{
b3=b1+stepb*i;
}
else
{
b3=b1-stepb*i;
}
Canvas->Brush->Color=RGB(r3,g3,b3);
Canvas->FillRect(BandRect);
} |
|
| Volver arriba |
|
 |
tyloya Master

Registrado: 20 Ago 2002Mensajes: 175
|
Publicado: Mie 04 Sep, 2002 9:16 am Asunto: Re: Degradee |
|
|
| Alfredo escribió: | Hola, Prueba esto para actuar sobre un Form o cualquier objeto con acceso a la propiedad Canvas.
Ponlo en cualquier evento, preferible onPaint
float Step, stepr,stepg, stepb;
TColor cInicial=clWhite;
TColor cFinal=clBlack;
TRect BandRect;
int Orientacion=2;//1=Vertical
//2=Horiontal
int r1=GetRValue((unsigned long)cInicial);
int g1=GetGValue((unsigned long)cInicial);
int b1=GetBValue((unsigned long)cInicial);
int r2=GetRValue((unsigned long)cFinal);
int g2=GetGValue((unsigned long)cFinal);
int b2=GetBValue((unsigned long)cFinal);
int r3,g3,b3;
stepr=(float)(r1-r2)/256;
stepg=(float)(g1-g2)/256;
stepb=(float)(b1-b2)/256;
if (Orientamento==1)
{
Step=(float)Height/256;
}
else
{
Step=(float)Width/256;
}
for(int i=0;i<256;i++)
{
if (Orientacion==1)
{
BandRect.Left=0;
BandRect.Top=(int)(i*Step);
BandRect.Right=Width+1;
BandRect.Bottom=(int)((i+1)*Step);
}
else
{
BandRect.Left=(int)(i*Step);
BandRect.Top=0;
BandRect.Right=(int)((i+1)*Step);
BandRect.Bottom=Height+1;
}
if ((r1<r2))
{
r3=r1+stepr*i;
}
else
{
r3=r1-stepr*i;
}
if (g1<g2)
{
g3=g1+stepg*i;
}
else
{
g3=g1-stepg*i;
}
if (b1<b2)
{
b3=b1+stepb*i;
}
else
{
b3=b1-stepb*i;
}
Canvas->Brush->Color=RGB(r3,g3,b3);
Canvas->FillRect(BandRect);
} |
Gracias por la ayuda...esto crea perfectamente una escala de grises.
El problema es q lo que quiero es que en cada componente, para una matriz de componentes que tengan asociada la propiedad Canvas, muestre
uno de estos colores según yo quiera, es decir, asignarle un color que no sea de forma aleatoria y asociarles un número entre 16 y 236, para poder aplicar un algoritmo que trabaje con el valor numérico de cada color.
GRACIAS OTRA VEZ |
|
| Volver arriba |
|
 |
|
|
No puedes publicar temas nuevos en este foro No puedes responder a temas en este foro No puedes editar tus mensajes en este foro No puedes borrar tus mensajes en este foro No puedes votar en las encuestas de este foro
|
© 2002–2026 Club Builder · Funciona con phpBB.
|