首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

DelphiX 實戰:TDIB.SephiaEffect 懷舊棕褐色調效果

     編輯:Delphi

TDIB.SephiaEffect 將影像轉換為經典的棕褐色調(Sepia),模擬老照片質感。單一參數控制效果強度,本文提供載入圖片後一鍵套用的最小範例。

效果預覽

SephiaEffect 效果

核心程式碼

unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DIB, StdCtrls;
type
  TForm1 = class(TForm)
    DXPaintBox1: TDXPaintBox;
    Button1: TButton; // 載入圖片
    Button2: TButton; // 套用懷舊效果
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;
var Form1: TForm1;
implementation {$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const ImgPath1 = 'C:\Temp\DX.jpg';
begin
  DXPaintBox1.DIB.LoadFromFile(ImgPath1);
  DXPaintBox1.Width := DXPaintBox1.DIB.Width;
  DXPaintBox1.Height := DXPaintBox1.DIB.Height;
  DXPaintBox1.Repaint;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  // SephiaEffect(Intensity: Integer)
  DXPaintBox1.DIB.SephiaEffect(20);
  DXPaintBox1.Repaint;
end;
end.

參數說明

  • Intensity (Integer):效果強度,範例值 20 為中等濃度
  • 就地修改,將 RGB 映射至棕褐色調色盤
  • 典型公式(近似):R' = 0.393R + 0.769G + 0.189B 等,再按強度與原色插值

視覺效果

  • 黑白照片著色:高光→淡黃、中調→棕褐、陰影→深棕
  • 強度越高 → 色彩飽和度越低、棕褐感越重
  • 強度 0 = 原圖,強度極大 ≈ 單色棕褐

應用場景

  • **懷舊/復古濾鏡**:相機 App、相簿編輯
  • **劇情回憶殺**:遊戲/動畫回憶片段視覺區隔
  • **文件古董化**:模擬泛黃紙張、褪色照片
  • **藝術風格化**:蒸汽龐克、西部片、年代感 UI

進階:可調色調的 Sepia


procedure CustomSepia(DIB: TDIB; TintColor: TColor; Amount: Single);
var x, y: Integer; c: TRGBQuad; gray: Byte; tr, tg, tb: Byte;
begin
  tr := GetRValue(TintColor); tg := GetGValue(TintColor); tb := GetBValue(TintColor);
  for y := 0 to DIB.Height - 1 do
    for x := 0 to DIB.Width - 1 do begin
      c := DIB.Pixels[x, y];
      gray := Round(0.299*c.rgbRed + 0.587*c.rgbGreen + 0.114*c.rgbBlue);
      c.rgbRed := Round(gray * (1-Amount) + tr * Amount);
      c.rgbGreen := Round(gray * (1-Amount) + tg * Amount);
      c.rgbBlue := Round(gray * (1-Amount) + tb * Amount);
      DIB.Pixels[x, y] := c;
    end;
end;

可產生藍調(青otype)、綠調(夜視儀)、紅調(熱成像)等變體。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved