ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 changing the brightness
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

papa.john

10 Posts

Posted - Nov 26 2024 :  03:15:00  Show Profile  Reply
Hi

My task is to smoothly darken the image in ImageEnView and also smoothly return it to its original state (as in the example below). I want to do this on a timer, gradually adding +1 or -1 to the brightness value of the image. What value in ImageEnView is responsible for brightness?



xequte

38684 Posts

Posted - Nov 26 2024 :  03:31:53  Show Profile  Reply
Hi

To adjust the brightness on the fly, you should just set the channel offset for all three channels:

http://www.imageen.com/help/TIEBitmap.ChannelOffset.html

This is shown in the demo:

Demos\Display\DisplayAdjust\Display.dpr

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

papa.john

10 Posts

Posted - Nov 26 2024 :  04:19:13  Show Profile  Reply
Not quite what I needed. In the Demo the colors remain somehow too saturated, while in my first example they actually darken.


Go to Top of Page

xequte

38684 Posts

Posted - Nov 26 2024 :  23:20:51  Show Profile  Reply
OK, in that case you should use AdjustBrightnessContrastSaturation on a temporary bitmap:

http://www.imageen.com/help/TImageEnProc.AdjustBrightnessContrastSaturation.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

papa.john

10 Posts

Posted - Nov 26 2024 :  23:53:00  Show Profile  Reply
Is there any other methods? AdjustBrightnessContrastSaturation darkens the picture the way I need it, but this method not good for gradual changing brighness on Timer because there is no origin value which I could decrease/increase. I also tried to add a Layer (black rectangle) and change its Transparancy on Timer, but it's too slow and freezing for my task.
Go to Top of Page

xequte

38684 Posts

Posted - Nov 27 2024 :  16:26:27  Show Profile  Reply
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
Go to Top of Page

papa.john

10 Posts

Posted - Nov 27 2024 :  22:45:15  Show Profile  Reply
Just what I needed! Thanks a lot!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: