将图片自己转换成BMP并缩放保存。

 
  1. //只支持jpeg、bmp 格式
  2. uses jpeg
  3. procedure SmoothResize(var TargetBmp:TBitmap; SourceBmp : TBitmap ; frameColor:TColor =-1);
  4. begin
  5.   SetStretchBltMode(TargetBmp.Canvas.Handle,STRETCH_HALFTONE);
  6.   StretchBlt(TargetBmp.Canvas.Handle,0,0,TargetBmp.Width,TargetBmp.Height,SourceBmp.Canvas.Handle,0,0,SourceBmp.Width,SourceBmp.Height,SRCCOPY);
  7.   if frameColor >-1 then  begin
  8.     TargetBmp.Canvas.Brush.Color := frameColor;
  9.     TargetBmp.Canvas.FrameRect(Rect(0,0,TargetBmp.Width,TargetBmp.Height ));
  10.   end;
  11. end;
  12. function DateTimeTOString(dt:TDateTime):shortstring;
  13. begin
  14.   Result :=formatDatetime('yyyymmddhhmmss',dt);
  15. end;
  16. //使用
  17. procedure TfrmWorkerEdit.SpeedButton1Click(Sender: TObject);
  18. var
  19.   bmp1 ,bmp2 : TBitmap;
  20.   jpg1 : TJPEGImage;
  21.   PhotoPath ,fn :string;
  22. begin
  23.   bmp1 := TBitmap.Create;
  24.   bmp2 := TBitmap.Create;
  25.   try
  26.     bmp1.Width := Image1.Width;
  27.     bmp1.Height :=Image1.Height ;
  28.     PhotoPath := ExtractFilePath(ParamStr(0))+'photo/';
  29.     if not DirectoryExists(PhotoPath) then CreateDir(PhotoPath);
  30.     with fDM.OpenDialog1  do begin
  31.       Title :='请选择文件';
  32.       Filter :='所支持的图片格式(*.jpg;*.JPEG;*,bmp)|*.jpg;*.JPEG;*,bmp';  
  33.     end;
  34.     if fDM.OpenDialog1.Execute  then
  35.       fn := fDM.OpenDialog1.FileName;
  36.     if not FileExists(fn) then Exit;
  37.     if (UpperCase(ExtractFileExt(fn))='.JPG'or
  38.        (UpperCase(ExtractFileExt(fn))='.JPEG'then begin
  39.           jpg1 :=TJPEGImage.Create;
  40.           try
  41.             jpg1.LoadFromFile(fn);
  42.             bmp2.Assign(jpg1);
  43.           finally
  44.             jpg1.Free;
  45.           end;
  46.     end else begin
  47.       bmp2.LoadFromFile(fn);
  48.     end;
  49.     SmoothResize(bmp1,bmp2,clBlue );
  50.     Image1.Picture.Bitmap := bmp1;
  51.     bmp1.SaveToFile(PhotoPath + DateTimeTOString(Now())+'.bmp') ;
  52.   finally
  53.     bmp1.Free;
  54.     bmp2.Free;
  55.   end;   
  56. end;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值