2010-05-07 265 views
5

我在带有256x256位图的TImage上使用Stretched = True。这会被缩小1,2,4或8倍。正如所料,离开'1'后,位图上的文字变得更可怕。 我注意到,虽然Windows 7资源管理器呈现了一个缩小版本的位图“更柔和”,更令人愉快。这样可以“模糊”TBitmap吗?是否可以在Delphi中平滑缩放的TBitmap?

回答

8

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

不幸的是TImage没有内置重新采样器,当涉及到调整其中的图像。 我的建议是使用Graphics32,因为它支持多种重新采样的(有些是增加大小他人减少尺寸更好)

+0

谢谢,更正了文字。好的建议重新Graphics32。 – 2010-05-07 13:12:35

9

通过使用半色调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; 
+0

很好的建议,谢谢。 – 2010-05-10 15:49:38

+0

@BrianFrost HALFTONE或STRETCH_HALFTONE是你最好的选择,恕我直言,这是一些代码http://code.google.com/p/delphigeist-delphi-stuff/source/browse/trunk/SynMiniMap/src/SynMiniMap.pas – ComputerSaysNo 2012-09-17 17:24:55

相关问题