Graphic Delphi

Title: How to load a JPEG to a TBitmap for easy editing
Question: Wondering howto load a JPG to a TBitmap?? Maybe not the most usefull codesnip, but I discovered many uses... This unit contains a TDRAWJpeg which can draw JPEGs to a canvas, and a procedure to load a JPEG to a TBitmap
Answer:
unit JPEGToTBitmap;
interface
uses Windows,Graphics,JPEG;
type
TDrawJPEG = class(TJPEGImage)
public
procedure Draw(ACanvas: TCanvas; const Rect: TRect); override;
end;
procedure LoadJPEGToTBitmap(Filename : string; Bitmap : TBitmap);
implementation
procedure TDrawJPEG.Draw(ACanvas: TCanvas; const Rect: TRect);
begin
inherited Draw(ACanvas,Rect);
end;
procedure LoadJPEGToTBitmap(Filename : string; Bitmap : TBitmap);
var
JPG : TDrawJPEG;
R : TRect;
begin
JPG:=TDrawJPEG.Create;
JPG.LoadFromFile(Filename);
Bitmap.Width:=JPG.Width;
Bitmap.Height:=JPG.Height;
R.Left:=0;
R.Top:=0;
R.Bottom:=JPG.Height;
R.Right:=JPG.Width;
JPG.Draw(Bitmap.Canvas,R);
JPG.Free;
end;
end.
//ENJOY!