首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

想做一个类似大头贴的软件,不知道怎么将图像框和头像的合并

2012-05-20 
想做一个类似大头贴的软件,不知道如何将图像框和头像的合并两幅图片,一张作为外观装饰,一张人物,人物可以

想做一个类似大头贴的软件,不知道如何将图像框和头像的合并
两幅图片,一张作为外观装饰,一张人物,人物可以移动,旋转,缩放。处理完后将其合并并且可以打印

[解决办法]
var FImgView : TImage32;
aLayer : TRotLayer;
begin
FImgView := timage32.create(self);
aLayer := TRotLayer.Create(FImgView.Layers);
with alayer do
begin
Bitmap.SetSize(width,height);
Angle := FAngle; //整个图像的角度
Bitmap.BeginUpdate;
Bitmap.DrawMode := dmBlend;
//FDrawX,FDrawY,FDrawW,FDrawH 图像在图层中的坐标和大小
DrawImage(FFileName,Bitmap.Canvas.Handle,GpRect(FDrawX,FDrawY,FDrawW,FDrawH)); 
SetBorderTransparent(Bitmap, Rect(0, 0, Bitmap.Width + 1, Bitmap.Height + 1 ));
BitmapCenter := FloatPoint(Bitmap.Width / 2, Bitmap.Height / 2);

Bitmap.StretchFilter := sfLinear;
//FLayerX,FLayerY 图层在FImgView 坐标系中的坐标
Position := FloatPoint(Bitmap.Width / 2 + FLayerX,Bitmap.Height / 2 + FLayerY);
Bitmap.MasterAlpha := FAlpha;//整体通明度
Bitmap.EndUpdate;
Bitmap.Changed;
MouseEvents := True; //响应鼠标事件
OnMouseDown := OnLayerMouseDown;
OnMouseMove := OnLayerMouseMove;//移动
OnMouseUp := OnLayerMouseUp;
end;
end;

//通过GDI+中的 TGpMatrix 可将图像在目标画布上旋转
procedure DrawImage(sFile : string;DC: HDC;aRect : TGpRectF);
var Gd : TGpGraphics;
GpBmp : TGpBitmap;
begin
if not FileExists(sFile) then Exit;
Gd := TGpGraphics.Create(DC);
GpBmp := TGpBitmap.Create(sFile);
Gd.DrawImage(GpBmp,aRect,0,0,GpBmp.Width,GpBmp.Height,utPixel);
Gd.Free;
GpBmp.Free;
end;

先画人像,再画边框

保存:
var Bitmap: tbitmap32;
FImgView.PaintTo(Bitmap,Bitmap.ClipRect);
[解决办法]
楼主你要熟悉Canvas画布操作即可,如果想支持多种格式需要用到GDI+。图像合并是很简单的东西,DELPHI有现成的方法,向画布画出即可,无论你有多少图片都可以画到画布上,然后保存画布,就等于合并了。

热点排行