![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#3
|
|||
|
|||
|
Mezclar imagenes
Hola JXJ.... existe una rutina muy interesante de un tal Yurii Zhukow que te permite mezclar 2 puntos en RGB mediante un valor de Alpha a una velocidad más que aceptable...
Acá te dejo la rutina con una pequeña modificación porque restaba 1 a cada color cada vez que hacías una mezcla.. mi aporte es nada comparado con lo brillante de la rutina del señor Zhukow function MixBytes(FG, BG, TRANS: byte): byte; asm push bx // push some regs push cx push dx mov DH,TRANS // remembering Transparency value (or Opacity - as you like) mov BL,FG // filling registers with our values mov AL,DH // BL = ForeGround (FG) mov CL,BG // CL = BackGround (BG) xor AH,AH // Clear High-order parts of regs xor BH,BH xor CH,CH mul BL // AX=AL*BL mov BX,AX // BX=AX xor AH,AH mov AL,DH xor AL,$FF // AX=(255-TRANS) mul CL // AX=AL*CL add AX,BX // AX=AX+BX and AL, 1 // ----> Agregado por FENIXadr add AH, AL // ----> Agregado por FENIXadr shr AX,8 // Fine! Here we have mixed value in AL pop dx // Hm... No rubbish after us, ok? pop cx pop bx // Bye, dear Assembler - we go home to Delphi! end; una vez que tengas esta rutina, podrás usarla de la siguiente manera: type TRGBTripleArray = array[word] of TRGBTriple; // "TRGBTriple" está en la Unit "Windows" PRGBTripleArray = ^TRGBTripleArray; ........ ......... ....... Procedure TForm1.Button1Click(Sender: TObject); var x, y : Integer; ScanFrom, ScanTo : PRGBTripleArray; Alpha : Byte; begin Img1.PixelFormat := pf24Bit; // MUY IMPORTANTE Img2.PixelFormat := pf24Bit; // MUY IMPORTANTE // Img1 e Img2 son de tipo TBitMap Alpha := 128; for y := 0 to Img1.Height - 1 do begin ScanFrom := Img1.ScanLine[y]; ScanTo := Img2.ScanLine[y]; for x := 0 to Img1.Width - 1 do begin ScanTo[x].rgbtBlue := MixBytes (ScanTo[x].rgbtBlue, ScanFrom[x].rgbtBlue, Alpha); ScanTo[x].rgbtGreen := MixBytes (ScanTo[x].rgbtGreen, ScanFrom[x].rgbtGreen, Alpha); ScanTo[x].rgbtRed := MixBytes (ScanTo[x].rgbtRed, ScanFrom[x].rgbtRed, Alpha); end; end; end; De esta manera ya puedes mezclar dos imágenes con solo modificar Alpha de 0 a 255, que las imágenes suban, bajen, se dezplacen hacia un lado u otro dependerá de tu código. Solo dos cosas hay que tenes en cuenta : Primero: Como puse arriba muy importante la propiedad PixelFormat debe ser pf24Bit sino funcionan muy mal los ScanLine`s Y Segundo : Que los ScanLine's no salgan fuera de la imagen porque se genera un error.. Espero que esto te ayude, cualquier cosa por aca andamos.. |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| Mover imagenes creadas en tiempo de ejecucion en lazarus | Guy Fawkes | Lazarus, FreePascal, Kylix, etc. | 1 | 14-01-2010 19:09:14 |
| Mover archivo | REHome | .NET | 5 | 22-05-2007 09:52:24 |
| mover el focus | ercrizeporta | Varios | 3 | 01-10-2006 00:38:42 |
| Mover componentes | Perrero80 | OOP | 4 | 17-05-2006 11:47:40 |
| Impedir mover el form y redimensionar al mover barra tareas | jealousy | API de Windows | 0 | 15-06-2004 12:58:05 |
|