Y
ynduanlian
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了这个函数来产生一个BMP的水平镜像图:
function MirrorBmp(const SBmp: TBitmap): TBitmap;
var
RBmp: TBitmap;
I: Integer;
begin
Result:=nil;
RBmp:=TBitmap.Create;
RBmp.Width:=Sbmp.Width;
RBmp.Height:=Sbmp.Height;
if (SBmp <> nil) then
begin
for I:=0 to SBmp.Width do
SBmp.Canvas.CopyRect(Rect(SBmp.Width-I,0,SBmp.Width-I,SBmp.Height),RBmp.Canvas,Rect(I,0,I,Sbmp.Height));
Result:=RBmp;
end;
end;
函数的调用:
procedure TfrmMain.Button1Click(Sender: TObject);
var
SBmp: TBitmap;
DBmp: TBitmap;
begin
SBmp:=TBitmap.Create;
DBmp:=TBitmap.Create;
SBmp.LoadFromFile('C:/1.bmp');
DBmp:=MirrorBmp(SBmp);
if (DBmp <> nil) then
DBmp.SaveToFile('C:/2.bmp');
end;
结果发现C:/2.bmp总是一张空白图,问题出在哪里啊?
function MirrorBmp(const SBmp: TBitmap): TBitmap;
var
RBmp: TBitmap;
I: Integer;
begin
Result:=nil;
RBmp:=TBitmap.Create;
RBmp.Width:=Sbmp.Width;
RBmp.Height:=Sbmp.Height;
if (SBmp <> nil) then
begin
for I:=0 to SBmp.Width do
SBmp.Canvas.CopyRect(Rect(SBmp.Width-I,0,SBmp.Width-I,SBmp.Height),RBmp.Canvas,Rect(I,0,I,Sbmp.Height));
Result:=RBmp;
end;
end;
函数的调用:
procedure TfrmMain.Button1Click(Sender: TObject);
var
SBmp: TBitmap;
DBmp: TBitmap;
begin
SBmp:=TBitmap.Create;
DBmp:=TBitmap.Create;
SBmp.LoadFromFile('C:/1.bmp');
DBmp:=MirrorBmp(SBmp);
if (DBmp <> nil) then
DBmp.SaveToFile('C:/2.bmp');
end;
结果发现C:/2.bmp总是一张空白图,问题出在哪里啊?