LoadFromFile (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses a button on a form and creates two bitmaps dynamically. One bitmap is monochrome, which means all nonwhite colors become black. The bitmap file path is relative to the Debug directory.

Code

procedure TForm1.Button1Click(Sender: TObject);
var
 BitMap1,BitMap2 : TBitMap;
 MyFormat : Word;
begin
   BitMap2 := TBitMap.Create;
   BitMap1 := TBitMap.Create;
try
   BitMap1.LoadFromFile('factory.bmp');
   BitMap2.Assign(BitMap1);     // Copy BitMap1 into BitMap2.
   BitMap2.Dormant;             // Free up GDI resources.
   BitMap2.FreeImage;           // Free up Memory.
   Canvas.Draw(20,20,BitMap2);  // Note that previous calls do not lose the image.
   BitMap2.Monochrome := true;
   Canvas.Draw(80,80,BitMap2);
   BitMap2.ReleaseHandle;       // This will actually lose the bitmap.
 finally
   BitMap1.Free;
   BitMap2.Free;
 end;
end;

Uses