读书人

柔光效果(请饭桶大哥指点,加急),该如何

发布时间: 2012-03-22 17:43:57 作者: rapoo

柔光效果(请饭桶大哥指点,加急)
实现光影里面的柔光效果
请高手指点

[解决办法]

Delphi(Pascal) code
function IntToByte(i: Integer): Byte;begin  if i > 255 then    Result := 255  else if i < 0 then    Result := 0  else    Result := i;end;procedure SplitBlur(var clip: tbitmap; Amount: integer);var  p0, p1, p2: pbytearray;  cx, i, x, y: Integer;  Buf: array[0..3, 0..2] of byte;begin  if Amount = 0 then Exit;  for y := 0 to clip.Height - 1 do  begin    p0 := clip.scanline[y];    if y - Amount < 0 then      p1 := clip.scanline[y]    else {y-Amount>0}      p1 := clip.ScanLine[y - Amount];    if y + Amount < clip.Height then      p2 := clip.ScanLine[y + Amount]    else {y+Amount>=Height}      p2 := clip.ScanLine[clip.Height - y];    for x := 0 to clip.Width - 1 do    begin      if x - Amount < 0 then        cx := x      else {x-Amount>0}        cx := x - Amount;      Buf[0, 0] := p1[cx * 3];      Buf[0, 1] := p1[cx * 3 + 1];      Buf[0, 2] := p1[cx * 3 + 2];      Buf[1, 0] := p2[cx * 3];      Buf[1, 1] := p2[cx * 3 + 1];      Buf[1, 2] := p2[cx * 3 + 2];      if x + Amount < clip.Width then        cx := x + Amount      else {x+Amount>=Width}        cx := clip.Width - x;      Buf[2, 0] := p1[cx * 3];      Buf[2, 1] := p1[cx * 3 + 1];      Buf[2, 2] := p1[cx * 3 + 2];      Buf[3, 0] := p2[cx * 3];      Buf[3, 1] := p2[cx * 3 + 1];      Buf[3, 2] := p2[cx * 3 + 2];      p0[x * 3] := (Buf[0, 0] + Buf[1, 0] + Buf[2, 0] + Buf[3, 0]) shr 2;      p0[x * 3 + 1] := (Buf[0, 1] + Buf[1, 1] + Buf[2, 1] + Buf[3, 1]) shr 2;      p0[x * 3 + 2] := (Buf[0, 2] + Buf[1, 2] + Buf[2, 2] + Buf[3, 2]) shr 2;    end;  end;end;procedure GaussianBlur(var clip: tbitmap; Amount: integer; Size: Integer = 3);var  i: Integer;begin  for i := Amount downto 0 do    SplitBlur(clip, Size);end;procedure BmpAlphaBlend(var dBmp: TBitMap; sBmp: TBitmap; Pos: TPoint; Alpha: integer; TranColor: TColor = -1);type  tagRGBTRIPLE = packed record    rgbtBlue: Byte;    rgbtGreen: Byte;    rgbtRed: Byte;  end;  TRGBTriple = tagRGBTRIPLE;  PRGBTripleArray = ^TRGBTripleArray;  TRGBTripleArray = array[0..32767] of TRGBTriple;  function GetSLColor(pRGB: TRGBTriple): TColor;  begin    Result := RGB(pRGB.rgbtRed, pRGB.rgbtGreen, pRGB.rgbtBlue);  end;var  p0, p1: PRGBTripleArray;  r, g, b, p, x, y: Integer;begin  sBmp.PixelFormat := pf24bit;  dBmp.PixelFormat := pf24bit;  if TranColor = -1 then    TranColor := sBmp.Canvas.Pixels[0, 0];  for y := 0 to sBmp.Height - 1 do    if (y + Pos.y >= 0) and (y + Pos.Y < dBmp.Height) then    begin      p0 := dBmp.ScanLine[y + Pos.y];      p1 := sBmp.ScanLine[y];      for x := 0 to sBmp.Width - 1 do        if (x + pos.X >= 0) and (x + Pos.X < dBmp.Width) then          if GetSLCOlor(p1[x]) <> TranColor then          begin            p0[x + pos.X].rgbtRed := IntToByte((p0[x + pos.X].rgbtRed * (100 - Alpha) +              p1[x].rgbtRed * Alpha) div 100);            p0[x + pos.X].rgbtGreen := IntToByte((p0[x + pos.X].rgbtGreen * (100 - Alpha) +              p1[x].rgbtGreen * Alpha) div 100);            p0[x + pos.X].rgbtBlue := IntToByte((p0[x + pos.X].rgbtBlue * (100 - Alpha) +              p1[x].rgbtBlue * Alpha) div 100);          end;    end;end;procedure TForm1.Button1Click(Sender: TObject);var src, bmp: TBitmap;begin  src:=TBitmap.Create ;  src.LoadFromFile('c:\b.bmp');  bmp := TBitmap.Create;  bmp.Assign(src);  //柔化处理...  GaussianBlur(bmp, 50);  //半透明合成   BmpAlphaBlend(bmp, src, Point(0, 0), 50);  src.Assign(bmp);  //显示   Canvas.Draw(0,0,src );  bmp.Free;  src.Free ;end;
[解决办法]
地球淫 嘿嘿

读书人网 >.NET

热点推荐