是否可以在Delphi中平滑缩放的TBitmap?

Bri*_*ost 5 delphi image blur tbitmap stretched

我在具有256x256位图的TImage上使用Stretched = True.这会按比例缩小1,2,4或8.正如预期的那样,位图上的文字越多,我就越离"1".我注意到,虽然Windows 7资源管理器呈现缩小版本的位图"更柔和",更令人愉悦.是否有可能以这种方式"模糊"TBitmap?

小智 9

通过使用HALFTONE StretchBltMode,您将获得比正常stretchdraw更平滑的结果.这只适用于Windows 2000及更高版本

procedure SmoothResize();
var pt:TPoint;
    h: HDC;
begin
  h := imgMainPicture.Canvas.Handle;
  // Previous call to StretchDraw
  // imgMainPicture.Canvas.StretchDraw(Rect(0, 0, imgMainPicture.Width - 1,
  // imgMainPicture.Height - 1), curPicture.AnnotatedBitmap);
  // Normal StretchDraw uses STRETCH_DELETESCANS as StretchBltMode , HALFTONE should give better results
  GetBrushOrgEx(h, pt);
  SetStretchBltMode(h, HALFTONE);
  SetBrushOrgEx(h, pt.x, pt.y, @pt);
  StretchBlt(h, 0, 0, imgMainPicture.Width - 1,
    imgMainPicture.Height - 1, curPicture.AnnotatedBitmap.Canvas.Handle,
    0, 0, curPicture.Width,curPicture.Height,SRCCOPY);
end;
Run Code Online (Sandbox Code Playgroud)


iam*_*osy 8

我想你的意思是在TImage上的Stretched = True,而不是在TBitmap上.

不幸的是,在调整图像大小时,TImage没有内置的重新采样器.我的建议是使用Graphics32,因为它支持各种重采样器(有些更适合增加其他尺寸以减小尺寸)