2010-05-07 50 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

相關問題