原图:
http://www.bababian.com/photozoom.sl?pictureid=7CEED87EE91F85BF193ABB6D2C16BE3ADT&size=6&viewID=B9924E01B43BE3150FA486950EE24C75UR
我处理的图:
http://www.bababian.com/picturedetail.sl?viewID=B9924E01B43BE3150FA486950EE24C75UR&pictureID=52C2DABB291415E5A9CB2C69A0C4406DDT&path=
问题:我处理的背景图跟原图一样,但是前景图(小动物)与原图还是有差距,怎样处理能达到原图的效果?

解决方案 »

  1.   

    1.用GDI+做,因为支持PNG这样的图片,所以只需要在PS上处理好后就可以了
    2.我自己曾经写过一个全透明与半透明合成的代码:function IntToByte(i: Integer): Byte;
    begin
      if i > 255 then
        Result := 255
      else if i < 0 then
        Result := 0
      else
        Result := i;
    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
      brBmp, srcBmp: TBitmap;
    begin
    //
      brBmp := TBitmap.Create;
      brBmp.LoadFromFile('c:\a.bmp');
      brBmp.PixelFormat := pf24bit;  srcBmp := TBitmap.Create;
      srcBmp.LoadFromFile('c:\b.bmp');
      srcBmp.PixelFormat := pf24bit;  BmpAlphaBlend(
        brBmp, //背景图(大图,也是结果图)
        srcBmp, //需要合成的小图
        Point(60, 60), //画小图的坐标
        100, //半透明度
        -1//需要透明的颜色(用于不规则图形,-1就表示以0,0位置的颜色为透明色)
        );  canvas.Draw(0, 0, brBmp);
      brBmp.Free;
      srcBmp.Free;
    end;