如何将获得的bmp、gif、png、tif等图片文件转换成自定大小的jpg格式文件?(100分)

  • 主题发起人 主题发起人 zk1
  • 开始时间 开始时间
Z

zk1

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将获得的bmp、gif、png、tif等图片文件转换成自定大小的jpg格式文件?

比如,对方的bmp文件为2024 X 1077大小的图片,如何将其转换为640 X 480 大小的jpg

格式图片呢?请写出代码!谢谢!
 
第一步:
安装 GraphicEx
http://www.delphicity.net/component.asp?componentid=330
它使Delphi能显示几乎所有格式的图片(只需引用单元,无须安装额外的控件)

第二步:
uses clipbrd,jpeg;

procedure TForm1.Button1Click(Sender: TObject);
var bitmap,map:tbitmap;
arect,brect:trect;
w,h,tw,th,tem:integer;
s:string;
begin
w:=640; //缩略图宽
h:=480; //缩略图高
Bitmap := TBitmap.Create;
map := TBitmap.Create;
s:=('D:/Documents and Settings/Administrator/My Documents/My Pictures/wen1.jpg');
image1.picture.LoadFromFile(s);
tw:=image1.Picture.Width;
th:=image1.Picture.height;
Clipboard.Assign(Image1.Picture);
map.LoadFromClipBoardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);
bitmap.Width :=w;
bitmap.height:=h;
{
下面的代码是画边框和阴影的,可以去掉
bitmap.Canvas.Brush.Color := clBtnFace;
brect.Left := 0;
brect.Top := 0;
brect.Right :=w;
brect.Bottom := h;
bitmap.Canvas.FillRect(brect);
bitmap.Canvas.Brush.Color := clBtnShadow;
bitmap.Canvas.FrameRect(brect);
bitmap.Canvas.MoveTo(0,0);
bitmap.Canvas.Pen.Color := clWhite;
bitmap.Canvas.LineTo(w,0);
bitmap.Canvas.MoveTo(0,0);
bitmap.Canvas.LineTo(0,h);
}
//bitmap.Canvas.Rectangle(brect);
if(tw<w)and(th<h) then
bitmap.canvas.Draw(w div 2-tw div 2+5,h div 2-th div 2+5,map)
else
begin
if tw>th then
begin
arect.left:=5;
arect.Right:=w-5;
tem:=round(w*(th/tw));
arect.top:=(h-tem) div 2+5;
arect.bottom:=arect.top+tem-5;
end
else
begin
arect.top:=5;
tem:=round(h*(tw/th));
arect.Left :=w div 2- tem div 2+5;
arect.Right:=arect.left+tem-5;
arect.bottom:=h-5;
end;
bitmap.Canvas.StretchDraw(arect,map)
end;
image1.Picture.Bitmap := bitmap;
image1.Picture.SaveToFile('c:/1.jpg');

end;
 
接受答案了.
 
后退
顶部