图象转换,如何保存?(50分)

H

Hecules

Unregistered / Unconfirmed
GUEST, unregistred user!
最近。想作个:图片的放大和缩小的程序,
我的思路是:
在:一个:Timage控件中,把:Stretch设置为:True.
这样,装入的图象,会自动按Timage控件调设置的Heigth 和 Width
来调整图像,
我只要:把:显示的图象,按:显示的大小,保存下来。就达到了:
图象的放大和缩小的目的。
但是,我用:
Image2.Picture.SaveToFile('new.bmp');
语句,来保存图象,发现,保存后的图象,还是原来的大小。
请教:如何?可以按Iimage的大小来保存图象呢?
 
Use StretchDraw() function draw on to a bitmap and then save as a file.
 
你可以这样:
procedure TForm1.BitBtn2Click(Sender: TObject);
var
bmp:Tbitmap;
begin
bmp:=Tbitmap.Create;
bmp.Width:=image1.Width;
bmp.Height:=image1.Height;
bmp.Canvas.CopyRect(rect(0,0,image1.Width,image1.Height),image1.Canvas,rect(0,0,bmp.Width,bmp.Height));
bmp.SaveToFile('e:/1.bmp');
bmp.free;
end;
end.
 
谢谢。
TO:cony,能否再详细点?
TO:huazai,你的方法,不行。我试过了。行不通呀。
 
//suppose your image is loaded in image1.
//something like below, i didn't test it on computer, maybe will encounter
//some problems, the thought should be right.
var
Bmp: TBitmap;
begin
Bmp:=TBitmap.Create;
Bmp.Width:= image1.width;
Bmp.Height:=image1.height;
Bmp.Canvas.StretchDraw(TRect(0,0,Bmp.width,bmp.height),Image1);
bmp.savetofile('c:/tmp.bmp');
bmp.free;
end;
 
同意,用StrechDraw画到另一个BMP里即可
 
谢谢,
但是,这样,只是:能:BMP图才可以。
对,JPG,JPEG,GIF没办法用。
再请教,如何处理,JPG,JPEG,GIF图?
另:我把一个图,缩小后,用缩小的图,来放大,会失真,
请教,如何处理这种情况?
 
对,JPG,JPEG,GIF没办法用。
Can convert these files to bmp file format. Or use some other
components. Because some GIF files are animate , I don't think
you zoom in or zoom out them except you don't want animate anymore.

另:我把一个图,缩小后,用缩小的图,来放大,会失真,
请教,如何处理这种情况?

Need backup the original image. Any zoom in or zoom out operation
should based on the original image.
 
看一下代码,是将bmp转换为jpg的代码: 看看对你是否有用!
procedure TForm1.Button1Click(Sender: TObject);
var
jp: TJpegImage; // 在uses中叙加入jpeg单元。.
begin
jp := TJpegImage.Create;
try
with jp do
begin
Assign(Image1.Picture.Bitmap);
Image2.Picture.Assign(jp);
SaveToFile('d:/tmp.jpg');
end;
finally
jp.Free;
end;
end;

end.
 
看一下代码,是将bmp转换为jpg的代码: 看看对你是否有用!
procedure TForm1.Button1Click(Sender: TObject);
var
jp: TJpegImage; // 在uses中叙加入jpeg单元。.
begin
jp := TJpegImage.Create;
try
with jp do
begin
Assign(Image1.Picture.Bitmap);
Image2.Picture.Assign(jp);
SaveToFile('d:/tmp.jpg');
end;
finally
jp.Free;
end;
end;

end.
 
多人接受答案了。
 
顶部