Ir al contenido


Foto

[TRUCO DELPHI] Atenuar / No Atenuar una Imagen.


  • Por favor identifícate para responder
2 respuestas en este tema

#1 sir.dev.a.lot

sir.dev.a.lot

    Advanced Member

  • Miembros
  • PipPipPip
  • 545 mensajes
  • Location127.0.0.1

Escrito 26 agosto 2016 - 08:55

[TRUCO DELPHI] Atenuar / No Atenuar una Imagen.

 

Declaracion de Tipos


delphi
  1. type
  2. PRGBTripleArray = ^TRGBTripleArray;
  3. TRGBTripleArray = array[0..32767] of TRGBTriple;


delphi
  1. //Atenuar
  2. procedure FadeIn(ImageFileName: TFileName);
  3. var
  4. Bitmap, BaseBitmap: TBitmap;
  5. Row, BaseRow: PRGBTripleArray;
  6. x, y, step: integer;
  7. begin
  8.  
  9. Bitmap := TBitmap.Create;
  10. try
  11. Bitmap.PixelFormat := pf32bit;
  12. Bitmap.LoadFromFile(ImageFileName);
  13. BaseBitmap := TBitmap.Create;
  14. try
  15. BaseBitmap.PixelFormat := pf32bit;
  16. BaseBitmap.Assign(Bitmap);
  17.  
  18. for step := 0 to 32 do
  19. begin
  20. for y := 0 to (Bitmap.Height - 1) do
  21. begin
  22. BaseRow := BaseBitmap.Scanline[y];
  23.  
  24. Row := Bitmap.Scanline[y];
  25.  
  26. for x := 0 to (Bitmap.Width - 1) do
  27. begin
  28. Row[x].rgbtRed := (step * BaseRow[x].rgbtRed) shr 5;
  29. Row[x].rgbtGreen := (step * BaseRow[x].rgbtGreen) shr 5;
  30. Row[x].rgbtBlue := (step * BaseRow[x].rgbtBlue) shr 5;
  31. end;
  32. end;
  33. Form1.Canvas.Draw(0, 0, Bitmap);
  34. InvalidateRect(Form1.Handle, nil, False);
  35.  
  36. RedrawWindow(Form1.Handle, nil, 0, RDW_UPDATENOW);
  37. end;
  38. finally
  39. BaseBitmap.Free;
  40. end;
  41. finally
  42. Bitmap.Free;
  43. end;
  44. end;
  45.  
  46. //No Atenuar
  47. procedure FadeOut(ImageFileName: TFileName);
  48. var
  49. Bitmap, BaseBitmap: TBitmap;
  50. Row, BaseRow: PRGBTripleArray;
  51. x, y, step: integer;
  52. begin
  53.  
  54. Bitmap := TBitmap.Create;
  55. try
  56. Bitmap.PixelFormat := pf32bit;
  57. Bitmap.LoadFromFile(ImageFileName);
  58. BaseBitmap := TBitmap.Create;
  59. try
  60. BaseBitmap.PixelFormat := pf32bit;
  61. BaseBitmap.Assign(Bitmap);
  62.  
  63. for step := 32 downto 0 do
  64. begin
  65. for y := 0 to (Bitmap.Height - 1) do
  66. begin
  67. BaseRow := BaseBitmap.Scanline[y];
  68.  
  69. Row := Bitmap.Scanline[y];
  70.  
  71. for x := 0 to (Bitmap.Width - 1) do
  72. begin
  73. Row[x].rgbtRed := (step * BaseRow[x].rgbtRed) shr 5;
  74. Row[x].rgbtGreen := (step * BaseRow[x].rgbtGreen) shr 5;
  75. Row[x].rgbtBlue := (step * BaseRow[x].rgbtBlue) shr 5;
  76. end;
  77. end;
  78. Form1.Canvas.Draw(0, 0, Bitmap);
  79. InvalidateRect(Form1.Handle, nil, False);
  80.  
  81. RedrawWindow(Form1.Handle, nil, 0, RDW_UPDATENOW);
  82. end;
  83. finally
  84. BaseBitmap.Free;
  85. end;
  86. finally
  87. Bitmap.Free;
  88. end;
  89. end;

Ejemplo de uso:


delphi
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3. FadeIn('C:\TestImage.bmp')
  4. end;

Saludos!


  • 1

#2 Delphius

Delphius

    Advanced Member

  • Administrador
  • 6.295 mensajes
  • LocationArgentina

Escrito 26 agosto 2016 - 09:21

¿El número 32 de donde sale? ¿Podría ser 16 por ejemplo?
Si no es mucha molestia ¿podrías subir unas imágenes donde se vean los efectos con el y sin el?

Aún no descargué la Starter para probar

Saludos
  • 0

#3 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 26 agosto 2016 - 09:55

Parte 4: Suavizando el cambio de imágenes.

 

Saludos.


  • 1




IP.Board spam blocked by CleanTalk.