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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 changing the brightness

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
papa.john Posted - Nov 26 2024 : 03:15:00
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?



6   L A T E S T    R E P L I E S    (Newest First)
papa.john Posted - Nov 27 2024 : 22:45:15
Just what I needed! Thanks a lot!
xequte Posted - Nov 27 2024 : 16:26:27
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
papa.john Posted - Nov 26 2024 : 23:53:00
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.
xequte Posted - Nov 26 2024 : 23:20:51
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
papa.john Posted - Nov 26 2024 : 04:19:13
Not quite what I needed. In the Demo the colors remain somehow too saturated, while in my first example they actually darken.


xequte Posted - Nov 26 2024 : 03:31:53
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