在Delphi中,是否有可能平滑缩放TBitmap?

7

我正在使用一个256x256位图的TImage,并将Stretched设置为True。这会使图像按1,2,4或8进行缩放。如预期的那样,离'1'越远,位图上的文本就变得越糟糕。 我注意到Windows 7资源管理器以更柔和、更令人愉悦的方式呈现了缩小版本的位图。是否有可能以这种方式“模糊”TBitmap?

2个回答

9

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

不幸的是,当涉及到在TImage中调整图像大小时,它没有内置的重新采样器。

我的建议是使用Graphics32,因为它支持各种重新采样器(有些更适合增大尺寸,有些更适合缩小尺寸)。


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;

@BrianFrost HALFTONE或STRETCH_HALFTONE是我个人认为最好的选择,这里有一些代码http://code.google.com/p/delphigeist-delphi-stuff/source/browse/trunk/SynMiniMap/src/SynMiniMap.pas - user497849

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接