TLama

Untitled

Feb 8th, 2014
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.08 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, ExtCtrls, PNGImage;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     PaintBox1: TPaintBox;
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure FormDestroy(Sender: TObject);
  14.     procedure PaintBox1Paint(Sender: TObject);
  15.   private
  16.     FBitmap: TBitmap;
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.dfm}
  27.  
  28. procedure TForm1.FormCreate(Sender: TObject);
  29. var
  30.   PNGImage: TPNGImage;
  31. begin
  32.   FBitmap := TBitmap.Create;
  33.   PNGImage := TPNGImage.Create;
  34.   try
  35.     PNGImage.LoadFromFile('C:\SomeFile.png');
  36.     FBitmap.Assign(PNGImage);
  37.   finally
  38.     PNGImage.Free;
  39.   end;
  40. end;
  41.  
  42. procedure TForm1.FormDestroy(Sender: TObject);
  43. begin
  44.   FBitmap.Free;
  45. end;
  46.  
  47. procedure TForm1.PaintBox1Paint(Sender: TObject);
  48. begin
  49.   // 128 in the fourth parameter is an example opacity value; it can be the value
  50.   // in the range of 0 to 255, where 255 is fully opaque rendering
  51.   PaintBox1.Canvas.Draw(0, 0, FBitmap, 128);
  52. end;
  53.  
  54. end.
Advertisement
Add Comment
Please, Sign In to add comment