OK, then you should use one of the paint events.
Add a trackbar to your demo with the range 0-100. Add this code to its Change event:
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
ImageEnView1.Update();
end;
Now you can either use the OnDrawBackBuffer event:
// 0=Black, 100=Full Brightness
procedure DarkenBitmap(Bitmap: TBitmap; BrightnessFactor: Integer);
type
TRGBTripleArray = ARRAY[Word] of TRGBTriple;
pRGBTripleArray = ^TRGBTripleArray;
var
x, y: Integer;
Row: PRGBTripleArray;
R, G, B: Byte;
begin
if ( Bitmap.PixelFormat <> pf24bit ) or ( BrightnessFactor < 0 ) or ( BrightnessFactor > 100 ) then
raise Exception.create( 'Cannot darken' );
for y := 0 to Bitmap.Height - 1 do
begin
Row := Bitmap.ScanLine[y];
for x := 0 to Bitmap.Width - 1 do
begin
// Get RGB components
R := Row[x].rgbtRed;
G := Row[x].rgbtGreen;
B := Row[x].rgbtBlue;
// Apply brightness scaling
Row[x].rgbtRed := Round( R * BrightnessFactor / 100.0 );
Row[x].rgbtGreen := Round( G * BrightnessFactor / 100.0 );
Row[x].rgbtBlue := Round( B * BrightnessFactor / 100.0 );
end;
end;
end;
procedure TForm1.ImageEnView1DrawBackBuffer(Sender: TObject);
begin
DarkenBitmap( ImageEnView1.BackBuffer, TrackBar1.Position );
end;
Or the OnDrawLayer event:
procedure TForm1.ImageEnView1DrawLayer(Sender: TObject; Dest: TIEBitmap; LayerIndex: Integer; DestRect: TRect);
var
brightness: Integer;
begin
brightness := TrackBar1.Position; // 0=Black, 100=Full Brightness
IEAdjustBrightnessContrastSaturation( Dest, Round(brightness * 2.56) { move into range 0-256}, 0, 256, nil, nil );
end;
Nigel
Xequte Software
www.imageen.com