unit BildLabel;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Graphics, Forms, StdCtrls;
type
TBildLabel =
class(TGraphicControl)
private
FPicture: TBitmap;
FAlphaValue: Byte;
procedure SetPicture(
const Value: TBitmap);
procedure SetAlphaValue(
const Value: Byte);
protected
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
procedure Paint;
override;
published
property Picture: TBitmap
read FPicture
write SetPicture;
property AlphaValue: Byte
read FAlphaValue
write SetAlphaValue;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
My Own', [TBildLabel]);
end;
{ TBildLabel }
constructor TBildLabel.Create(AOwner: TComponent);
begin
inherited;
FPicture := TBitmap.Create;
fAlphaValue := 0;
end;
destructor TBildLabel.Destroy;
begin
FPicture.Free;
inherited;
end;
procedure TBildLabel.Paint;
var Bitmap: TBitmap;
BlendFunction: TBlendFunction;
begin
//Buffer-Bitmap erstellen
Bitmap := TBitmap.Create;
Bitmap.Width := Width;
Bitmap.Height := Height;
//Picture in Buffer-Bitmap kopieren
Bitmap.Canvas.StretchDraw(Bitmap.Canvas.ClipRect,FPicture);
//Buffer-Bitmap in den Canvas laden
BlendFunction.BlendOp := AC_SRC_OVER;
BlendFunction.BlendFlags := 0;
BlendFunction.SourceConstantAlpha := fAlphaValue;
BlendFunction.AlphaFormat := 0;
windows.AlphaBlend(Canvas.Handle, 0, 0, Width, Height, Bitmap.Canvas.Handle,
0, 0, Width, Height, BlendFunction);
Bitmap.Free;
end;
procedure TBildLabel.SetAlphaValue(
const Value: Byte);
begin
if FAlphaValue <> Value
then begin
FAlphaValue := Value;
Invalidate;
end;
end;
procedure TBildLabel.SetPicture(
const Value: TBitmap);
begin
if FPicture <> Value
then begin
FPicture.Assign(Value);
Invalidate;
end;
end;
end.