将图片自己转换成BMP并缩放保存。
2008-11-06 11:57
609 查看
//只支持jpeg、bmp 格式
uses jpeg
procedure SmoothResize(var TargetBmp:TBitmap; SourceBmp : TBitmap ; frameColor:TColor =-1);
begin
SetStretchBltMode(TargetBmp.Canvas.Handle,STRETCH_HALFTONE);
StretchBlt(TargetBmp.Canvas.Handle,0,0,TargetBmp.Width,TargetBmp.Height,SourceBmp.Canvas.Handle,0,0,SourceBmp.Width,SourceBmp.Height,SRCCOPY);
if frameColor >-1 then begin
TargetBmp.Canvas.Brush.Color := frameColor;
TargetBmp.Canvas.FrameRect(Rect(0,0,TargetBmp.Width,TargetBmp.Height ));
end;
end;
function DateTimeTOString(dt:TDateTime):shortstring;
begin
Result :=formatDatetime('yyyymmddhhmmss',dt);
end;
//使用
procedure TfrmWorkerEdit.SpeedButton1Click(Sender: TObject);
var
bmp1 ,bmp2 : TBitmap;
jpg1 : TJPEGImage;
PhotoPath ,fn :string;
begin
bmp1 := TBitmap.Create;
bmp2 := TBitmap.Create;
try
bmp1.Width := Image1.Width;
bmp1.Height :=Image1.Height ;
PhotoPath := ExtractFilePath(ParamStr(0))+'photo/';
if not DirectoryExists(PhotoPath) then CreateDir(PhotoPath);
with fDM.OpenDialog1 do begin
Title :='请选择文件';
Filter :='所支持的图片格式(*.jpg;*.JPEG;*,bmp)|*.jpg;*.JPEG;*,bmp';
end;
if fDM.OpenDialog1.Execute then
fn := fDM.OpenDialog1.FileName;
if not FileExists(fn) then Exit;
if (UpperCase(ExtractFileExt(fn))='.JPG') or
(UpperCase(ExtractFileExt(fn))='.JPEG') then begin
jpg1 :=TJPEGImage.Create;
try
jpg1.LoadFromFile(fn);
bmp2.Assign(jpg1);
finally
jpg1.Free;
end;
end else begin
bmp2.LoadFromFile(fn);
end;
SmoothResize(bmp1,bmp2,clBlue );
Image1.Picture.Bitmap := bmp1;
bmp1.SaveToFile(PhotoPath + DateTimeTOString(Now())+'.bmp') ;
finally
bmp1.Free;
bmp2.Free;
end;
end;
uses jpeg
procedure SmoothResize(var TargetBmp:TBitmap; SourceBmp : TBitmap ; frameColor:TColor =-1);
begin
SetStretchBltMode(TargetBmp.Canvas.Handle,STRETCH_HALFTONE);
StretchBlt(TargetBmp.Canvas.Handle,0,0,TargetBmp.Width,TargetBmp.Height,SourceBmp.Canvas.Handle,0,0,SourceBmp.Width,SourceBmp.Height,SRCCOPY);
if frameColor >-1 then begin
TargetBmp.Canvas.Brush.Color := frameColor;
TargetBmp.Canvas.FrameRect(Rect(0,0,TargetBmp.Width,TargetBmp.Height ));
end;
end;
function DateTimeTOString(dt:TDateTime):shortstring;
begin
Result :=formatDatetime('yyyymmddhhmmss',dt);
end;
//使用
procedure TfrmWorkerEdit.SpeedButton1Click(Sender: TObject);
var
bmp1 ,bmp2 : TBitmap;
jpg1 : TJPEGImage;
PhotoPath ,fn :string;
begin
bmp1 := TBitmap.Create;
bmp2 := TBitmap.Create;
try
bmp1.Width := Image1.Width;
bmp1.Height :=Image1.Height ;
PhotoPath := ExtractFilePath(ParamStr(0))+'photo/';
if not DirectoryExists(PhotoPath) then CreateDir(PhotoPath);
with fDM.OpenDialog1 do begin
Title :='请选择文件';
Filter :='所支持的图片格式(*.jpg;*.JPEG;*,bmp)|*.jpg;*.JPEG;*,bmp';
end;
if fDM.OpenDialog1.Execute then
fn := fDM.OpenDialog1.FileName;
if not FileExists(fn) then Exit;
if (UpperCase(ExtractFileExt(fn))='.JPG') or
(UpperCase(ExtractFileExt(fn))='.JPEG') then begin
jpg1 :=TJPEGImage.Create;
try
jpg1.LoadFromFile(fn);
bmp2.Assign(jpg1);
finally
jpg1.Free;
end;
end else begin
bmp2.LoadFromFile(fn);
end;
SmoothResize(bmp1,bmp2,clBlue );
Image1.Picture.Bitmap := bmp1;
bmp1.SaveToFile(PhotoPath + DateTimeTOString(Now())+'.bmp') ;
finally
bmp1.Free;
bmp2.Free;
end;
end;
相关文章推荐
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byt
- Android 把bitmap转换成String,计算图片的缩放值,根据路径获得突破并压缩返回bitmap用于显示,获取保存 隐患检查的图片文件夹名称,获取保存图片的目录,根据路径删除图片,添加到图库
- 使用转换mnist数据库保存为bmp图片
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- vc++ mfc 里保存缩放的bmp图片 不失真
- 使用转换mnist数据库保存为bmp图片
- android 将图片内容解析成字节数组,将字节数组转换为ImageView可调用的Bitmap对象,图片缩放,把字节数组保存为一个文件,把Bitmap转Byte
- OpenGL保存bmp图片(字节对齐与RGB分量转换)
- java将图片缩放实现类(能将jpg、bmp、png、gif图片文件,进行等比或非等比的大小转换)
- OpenGL保存bmp图片(字节对齐与RGB分量转换)
- 保存一个免费的在线的图片转换工具网站,支持BMP,JPG,IOC,PNG和GIF
- vc++ mfc 里保存缩放的bmp图片 不失真
- JAVA图片处理--缩放,切割,类型转换
- mp3 音频 音乐 tag ID3 ID3V1 ID3V2 标签 读取信息 获得图片 jpeg bmp 图片转换等
- 利用libqrencode将二维码信息保存到bmp图片中
- Java关于图片的切割、缩放、类型转换、水印、彩色转黑白处理
- [代码收集] 窗口截屏并保存为bmp图片