比方说:我现在有一张图片A是JPG格式的图片,还有一张图片B是GIF格式的图片(注:B图片背景是透明的),我现在可以把A和B图片合并在一起生成一个新的JPG图片C,可以生成后的C图片,原来GIF图片的位置背景本来是透明的,现在变成白的了。怎么办啊?
我想要达到的图片效果是:http://www.yeagen.com/other/yes.jpg
而现在我只能达到的效果是:http://www.yeagen.com/other/no.jpg 以下是我合并时用的代码:
procedure TForm1.Button1Click(Sender: TObject);
var
JPEGImage1: TJPEGImage;
JPEGImage2: TGIFImage;
tmpImage1, tmpImage2 :TImage;
ARect :TRect;
AWidth, AHeight :integer;
begin
DoubleBuffered:=true;
tmpImage1 := TImage.Create(Self);
tmpImage2 := TImage.Create(Self);
tmpImage1.AutoSize:=true;
tmpImage2.AutoSize:=true;//先读入jpeg格式的图片
JPEGImage1 := TJPEGImage.Create;
JPEGImage1.LoadFromFile('d:\a.jpg');
tmpImage1.Picture.Bitmap.Assign(JPEGImage1);
JPEGImage2 := TGifImage.Create;
JPEGImage2.LoadFromFile('d:\bb.gif');
tmpImage2.Picture.Bitmap.Assign(JPEGImage2);
AWidth := tmpImage1.Width;
AHeight:= tmpImage1.Height;
tmpImage1.AutoSize:=false; bitblt(tmpimage1.Canvas.Handle,0,0,screen.Width,screen.Height,tmpimage2.Canvas.handle,0,0,srccopy);
JPEGImage1.Assign(tmpImage1.Picture.Bitmap);
JPEGImage1.Compress;
JPEGImage1.SaveToFile('d:\c.jpg');
tmpimage1.Free;
tmpimage2.Free;
JPEGImage1.Free;
JPEGImage2.Free;
end;
我想要达到的图片效果是:http://www.yeagen.com/other/yes.jpg
而现在我只能达到的效果是:http://www.yeagen.com/other/no.jpg 以下是我合并时用的代码:
procedure TForm1.Button1Click(Sender: TObject);
var
JPEGImage1: TJPEGImage;
JPEGImage2: TGIFImage;
tmpImage1, tmpImage2 :TImage;
ARect :TRect;
AWidth, AHeight :integer;
begin
DoubleBuffered:=true;
tmpImage1 := TImage.Create(Self);
tmpImage2 := TImage.Create(Self);
tmpImage1.AutoSize:=true;
tmpImage2.AutoSize:=true;//先读入jpeg格式的图片
JPEGImage1 := TJPEGImage.Create;
JPEGImage1.LoadFromFile('d:\a.jpg');
tmpImage1.Picture.Bitmap.Assign(JPEGImage1);
JPEGImage2 := TGifImage.Create;
JPEGImage2.LoadFromFile('d:\bb.gif');
tmpImage2.Picture.Bitmap.Assign(JPEGImage2);
AWidth := tmpImage1.Width;
AHeight:= tmpImage1.Height;
tmpImage1.AutoSize:=false; bitblt(tmpimage1.Canvas.Handle,0,0,screen.Width,screen.Height,tmpimage2.Canvas.handle,0,0,srccopy);
JPEGImage1.Assign(tmpImage1.Picture.Bitmap);
JPEGImage1.Compress;
JPEGImage1.SaveToFile('d:\c.jpg');
tmpimage1.Free;
tmpimage2.Free;
JPEGImage1.Free;
JPEGImage2.Free;
end;
解决方案 »
- 请问专家: DELPHI2007 中,有什么办法可以获取远程服务器的硬件信息,比如硬盘序列号,主板序列号或者CPU序列号等等.
- ★TStrings和TStringList有何相同和不同之处?
- sql server2000表如何导入excel表中
- 谁有< Broland传奇>,可以下截100分送
- 问个菜问题!
- 如何得到dbgrid中的单元格中的一个值,dbgrid中的单元格应该是一个二维数据吧?应该如何得到?
- Delphi如何提取网页链接和链接文本
- 怎样建一个INI文件?格式如何?
- 如何将数据库中的变量类型转成delphi的数据类型?
- delphi的不足?
- radiobutton出错.................................
- 简单问题,送分!!在线等
type
tagRGBTRIPLE = packed record
rgbtBlue: Byte;
rgbtGreen: Byte;
rgbtRed: Byte;
end;
TRGBTriple = tagRGBTRIPLE;
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array[0..32767] of TRGBTriple;
procedure BmpAlphaBlend(var dBmp: TBitMap; sBmp: TBitmap; Pos: TPoint; Alpha: integer; TranColor: TColor = -1);
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;