bmp位图缩放如何保持图像清晰不变型 本帖最后由 yct0605 于 2014-01-16 19:13:40 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 嗯,GDI+是可以的,GDI+中就有bicubic resample算法的缩放。 例子:http://www.codeproject.com/Articles/11143/Image-Resizing-outperform-GDI 下了一个是.net版本的啊,有没有D版本的 我写有二线插值算法的BMP位图缩放! 不过不变形估计很难! 图像清晰感觉还行! 参考一下,文字效果不是很好:procedure TledMain.ImgZoomIn;var Bmp:TBitmap; backBmp:TBitmap;begin try //动态创建位图 backBmp:=TBitmap.Create; //设置backBmp的宽度和高度 backBmp.Width:=Image1.Width; backBmp.Height:=Image1.Height; backBmp.PixelFormat:=pf24bit; //设置位图为24色位图 backBmp.Assign(Image1.Picture.Bitmap); Bmp:=TBitmap.Create; //产生Tbitmap对象Bmp Bmp.PixelFormat:=pf24bit; //设置bmp为24色位图 //Image1.AutoSize:=True; //缩小图像为原来的0.5倍,Trunc为取整函数 Bmp.Width:=Trunc(0.5*Image1.Width); Bmp.Height:=Trunc(0.5*Image1.Height); //保持最大限度不失真 SetStretchBltMode(Bmp.Canvas.Handle,HALFTONE); StretchBlt(Bmp.Canvas.Handle,0,0,Bmp.Width,Bmp.Height, backBmp.Canvas.Handle,0,0, backBmp.Width,backBmp.Height,SRCCOPY); Image1.Picture.Bitmap.Assign(Bmp); //设置图像居中显示 Image1.Top:=Self.Height div 2 -bmp.Height div 2; Image1.Left:=Self.Width div 2 -bmp.Height div 2; Bmp.PixelFormat:=pf24bit; Bmp.Free; Bmp:=nil; backBmp.Free; backBmp:=nil; Image1.Picture.SaveToFile(CurrentPath+'Out Bmp\led.bmp'); except on e:Exception do begin SetDlgAutoClose(1000,True); application.MessageBox(PChar('分割截图:'+e.Message),'错误',mb_iconstop); //ListBox1.Items.Clear; //ListBox1.Items.Add(e.Message); //ListBox1.items.SaveToFile(CurrentPath+FormatDateTime('yyyymmddhhmmss',Now)+'.log'); _stop.Click; Application.ProcessMessages; _update.Click; end; end;end; 这个很简单的,分分钟的事。uses WinAPI.GDIPAPI, WinAPI.GDIPOBJ;var Bitmap1: TGPBitmap; Bitmap2: TBitmap; Graphic: TGPGraphics;begin Bitmap1 := TGPBitmap.Create('test.bmp'); // bmp, gif, jpeg, png... Bitmap2 := TBitmap.Create; with Bitmap2 do begin Width := Bitmap1.GetWidth * 2 div 3; // shrink to 2/3 width Height := Bitmap1.GetHeight * 2 div 3; // shrink to 2/3 height PixelFormat := pf32bit; end; Graphic := TGPGraphics.Create(Bitmap2.Canvas.Handle); Graphic.SetInterpolationMode(InterpolationModeHighQualityBicubic); // bicubic resample Graphic.DrawImage(Bitmap1, 0, 0, Bitmap2.Width, Bitmap2.Height); Bitmap2.SaveToFile('test_resized.bmp'); Graphic.Free; Bitmap2.Free; Bitmap1.Free;end; 就像LS那样直接GDI+的又快又方便,除非你自己的算法更快 14楼的delphiguy不是给出了代码了么,简单明了就那么几行 效果还不是很好,估计需要降噪处理bicubic resample是到目前为止,位图缩放保持原图视觉效果最好的算法了,如果这还不是很好,那你的要求是不可达到的,你可以把“测试还可以”的效果拿出来比较一下。 窗体显示问题 如何列举某一进程的线程id列表 try...except 和 try...finally 的区别,请教各位。 寻求货物配送管理软件 有关DBGird的问题!!毕业设计中,请指教!! 明天考试救急 关于在word中插入图片的问题 设计一个多表单,同一数据导航、控制按钮的思路应是怎样的? 怎样确定光盘的存在及盘符???????? 急,如何将StringGrid的某一列设为又对齐 求助,循环读取两memo的内容!!! delphi中使用Lua的问题
procedure TledMain.ImgZoomIn;
var
Bmp:TBitmap;
backBmp:TBitmap;
begin
try
//动态创建位图
backBmp:=TBitmap.Create;
//设置backBmp的宽度和高度
backBmp.Width:=Image1.Width;
backBmp.Height:=Image1.Height;
backBmp.PixelFormat:=pf24bit; //设置位图为24色位图
backBmp.Assign(Image1.Picture.Bitmap); Bmp:=TBitmap.Create; //产生Tbitmap对象Bmp
Bmp.PixelFormat:=pf24bit; //设置bmp为24色位图
//Image1.AutoSize:=True;
//缩小图像为原来的0.5倍,Trunc为取整函数
Bmp.Width:=Trunc(0.5*Image1.Width);
Bmp.Height:=Trunc(0.5*Image1.Height);
//保持最大限度不失真
SetStretchBltMode(Bmp.Canvas.Handle,HALFTONE);
StretchBlt(Bmp.Canvas.Handle,0,0,Bmp.Width,Bmp.Height,
backBmp.Canvas.Handle,0,0,
backBmp.Width,backBmp.Height,SRCCOPY);
Image1.Picture.Bitmap.Assign(Bmp);
//设置图像居中显示
Image1.Top:=Self.Height div 2 -bmp.Height div 2;
Image1.Left:=Self.Width div 2 -bmp.Height div 2;
Bmp.PixelFormat:=pf24bit;
Bmp.Free;
Bmp:=nil;
backBmp.Free;
backBmp:=nil;
Image1.Picture.SaveToFile(CurrentPath+'Out Bmp\led.bmp');
except
on e:Exception do
begin
SetDlgAutoClose(1000,True);
application.MessageBox(PChar('分割截图:'+e.Message),'错误',mb_iconstop); //ListBox1.Items.Clear;
//ListBox1.Items.Add(e.Message);
//ListBox1.items.SaveToFile(CurrentPath+FormatDateTime('yyyymmddhhmmss',Now)+'.log'); _stop.Click;
Application.ProcessMessages;
_update.Click;
end;
end;
end;
这个很简单的,分分钟的事。uses WinAPI.GDIPAPI, WinAPI.GDIPOBJ;var
Bitmap1: TGPBitmap;
Bitmap2: TBitmap;
Graphic: TGPGraphics;
begin
Bitmap1 := TGPBitmap.Create('test.bmp'); // bmp, gif, jpeg, png...
Bitmap2 := TBitmap.Create;
with Bitmap2 do
begin
Width := Bitmap1.GetWidth * 2 div 3; // shrink to 2/3 width
Height := Bitmap1.GetHeight * 2 div 3; // shrink to 2/3 height
PixelFormat := pf32bit;
end;
Graphic := TGPGraphics.Create(Bitmap2.Canvas.Handle);
Graphic.SetInterpolationMode(InterpolationModeHighQualityBicubic); // bicubic resample
Graphic.DrawImage(Bitmap1, 0, 0, Bitmap2.Width, Bitmap2.Height);
Bitmap2.SaveToFile('test_resized.bmp');
Graphic.Free;
Bitmap2.Free;
Bitmap1.Free;
end;