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
 Values for real sepia?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

flatserv

Germany
22 Posts

Posted - Nov 22 2012 :  02:41:46  Show Profile  Reply
Hi,

i want to convert my Image into sepia, currently i use

ImageEnView1.Proc.Colorize(40, 50, 1.1);
ImageEnView1.Proc.IntensityRGBall(0,0,78);

Because there is no real "ConvertToSepia" function and my values (see above) are not perfect: Does anyone have better values? Or maybe ideas how to convert into better sepia?

Best regards

w2m

USA
1990 Posts

Posted - Nov 23 2012 :  07:47:54  Show Profile  Reply
Someone may have an ImageEn method to create Sepia effect, but here is another way:
function BmpToSepia(const ABitmap: TBitmap; ADepth: Integer): boolean;
//This function adds a sepia effect to a bitmap.
//Adepth sets the colour intensity of the red-brown color
//Greater ADepth values set a higher intensity.
//Usually ADepth values from 35-75 produce the best effect
//To create a greyscale effect, set ADepth to 0
var
  iColor: longint;
  iColor2: longint;
  r, g, b, rr, gg: byte;
  iWidth, iHeight: Integer;
begin
  Screen.Cursor := crHourGlass;
  try
    Result := False;
    begin
      for iHeight := 0 to ABitmap.Height do
      begin
        for iWidth := 0 to ABitmap.Width do
        begin
          //first convert the bitmap to greyscale
          iColor := ColorToRGB(ABitmap.Canvas.Pixels[iWidth, iHeight]);
          r := GetRValue(iColor);
          g := GetGValue(iColor);
          b := GetBValue(iColor);
          iColor2 := (r + g + b) div 3;
          ABitmap.Canvas.Pixels[iWidth, iHeight] := RGB(iColor2, iColor2, iColor2);
          //then convert it to sepia
          iColor := colortorgb(ABitmap.Canvas.Pixels[iWidth, iHeight]);
          r := GetRValue(iColor);
          g := GetGValue(iColor);
          b := GetBValue(iColor);
          rr := r + (ADepth * 2);
          gg := g + ADepth;
          if rr<=((ADepth * 2) - 1) then
            rr := 255;
          if gg<=(ADepth - 1) then
            gg := 255;
          ABitmap.Canvas.Pixels[iWidth, iHeight] := RGB(rr, gg, b);
        end;
        Result := True;
      end;
    end;
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  iDepth: Integer;
begin
  ImageEnView1.Proc.SaveUndoCaptioned('Sepia ' + IntToStr(ImageEnView1.Proc.UndoCount));
  Undo1.Hint := 'Sepia ' + IntToStr(ImageEnView1.Proc.UndoCount);
  iDepth := 3;
  iDepth := StrToIntDef(InputBox('Blur', 'Enter Sepia Level, IntToStr(iDepth)), 1);
  BmpToSepia(ImageEnView1.Bitmap, iDepth);
  ImageEnView1.Update;
  Undo1.Enabled := ImageEnView1.Proc.CanUndo;
  ImageEnView1.Bitmap.Modified := True;
end;


William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

flatserv

Germany
22 Posts

Posted - Nov 23 2012 :  08:26:27  Show Profile  Reply
Works fine, many thanks!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: