delphi 的图像缩放示例代码如下:
//将图片缩放至指定大小procedure SizeBmp(const Source, Dest: string const x, y: integer)
var
aBmp, bBmp: tbitmap
scalex, scaley: real
begin
aBmp := TBitmap.Create
bBmp := TBitmap.Create
try
aBmp.LoadFromFile(Source)
scaley := aBmp.Height / y
scalex := aBmp.Width / x
bBmp.Width := round(aBmp.Width / scalex)
bBmp.Height := round(aBmp.Height / scaley)
bBmp.PixelFormat := pfDevice
SetStretchBltMode(bBmp.Canvas.Handle, COLORONCOLOR)
StretchBlt(bBmp.Canvas.Handle, 0, 0, bBmp.Width, bBmp.Height,
aBmp.Canvas.Handle, 0, 0, aBmp.Width, aBmp.Height, srccopy)
bBmp.SaveToFile(Dest)
finally
aBmp.Free
bBmp.Free
end
end
procedure TForm1.btn1Click(Sender: TObject)
begin
SizeBmp('e:\1112.bmp','e:\1112_small.bmp',640,480)
end
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)