我有一个image已经打开了一个图片,想再打开的图片与他合并,如何实现?(100分)

  • 主题发起人 主题发起人 ylbee
  • 开始时间 开始时间
Y

ylbee

Unregistered / Unconfirmed
GUEST, unregistred user!
我的想法是:
先将image1中的图片拷贝到image2上,然后再将image2上的图片
拷贝到image1上半部分。
再将新图片装入image3,然后再将image3上的图片拷贝到image1下半部分。
我使用的bitblt可就是在image1上的图片很乱,而且只有原图片的一部分。
高手门给段代码,帮帮我
谢谢
 
高手在哪里?
 
想不想另图片有另一番效果,使用下列语句实现吧,增加两个Timage图片框,分别为Image1、Image2,用Image1引入一张图片,按下按钮就可以在Image2上出现惊人的效果
procedure TForm1.Button1Click(Sender: Tobject);
begin
Image2.Canvas.Brush.Style := bsCross;
Image2.Canvas.CopyMode := cmMergeCopy;
Image2.Canvas.Draw(0,0, Image1.Picture.Graphic);
end;
 
用 Image.picture.bitmap.canvas.CopyRect 方法比较好
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs;

type
TForm1 = class(TForm)
OpenPictureDialog1: TOpenPictureDialog;
Button1: TButton;
Image1: TImage;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure AddRight(const FileName: string);
procedure AddBottom(const FileName: string);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Image1.AutoSize:=True
end;

procedure TForm1.AddRight(const FileName: string);
var
Bitmap: TBitmap;
OldWidth: Integer;
begin
BitMap:=TBitmap.Create;
try
BitMap.LoadFromFile(FileName);
OldWidth:=Image1.Picture.Width;
Image1.AutoSize:=False;
Image1.Picture.Bitmap.Width:=Image1.Picture.Width+Bitmap.Width;
if Bitmap.Height>Image1.Picture.Height then
Image1.Picture.Bitmap.Height:=Bitmap.Height;
Image1.AutoSize:=True;
Image1.Canvas.CopyRect(Rect(OldWidth, 0, OldWidth+Bitmap.Width, Bitmap.Height),
Bitmap.Canvas, Rect(0, 0, Bitmap.Width, Bitmap.Height))
finally
Bitmap.Free
end
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
AddRight(OpenPictureDialog1.FileName)
end;

procedure TForm1.AddBottom(const FileName: string);
var
Bitmap: TBitmap;
OldHeight: Integer;
begin
BitMap:=TBitmap.Create;
try
BitMap.LoadFromFile(FileName);
OldHeight:=Image1.Picture.Height;
Image1.AutoSize:=False;
Image1.Picture.Bitmap.Height:=Image1.Picture.Height+Bitmap.Height;
if Bitmap.Width>Image1.Picture.Width then
Image1.Picture.Bitmap.Width:=Bitmap.Width;
Image1.AutoSize:=True;
Image1.Canvas.CopyRect(Rect(0, OldHeight, Bitmap.Width, OldHeight+Bitmap.Height),
Bitmap.Canvas, Rect(0, 0, Bitmap.Width, Bitmap.Height))
finally
Bitmap.Free
end
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
AddBottom(OpenPictureDialog1.FileName)
end;

end.
 
后退
顶部