Is it possible to smooth a scaled TBitmap in Delphi?
Asked Answered
S

2

7

I am using Stretched=True on a TImage with a 256x256 bitmap. This gets scaled down by 1,2,4 or 8. As expected, text on the bitmap gets more horrible the more I depart from '1'. I notice though that Windows 7 explorer renders a scaled down version of the bitmap 'softer' and more pleasing. Is it possible to 'blur' a TBitmap in this way?

Seditious answered 7/5, 2010 at 11:11 Comment(0)
F
9

I suppose you mean Stretched = True on a TImage, not on A TBitmap.

Unfortunately TImage has no resamplers built in, when it comes to resizing images in it. My recommendation would be to use Graphics32 as it supports a variety of resamplers (some are better for increasing size others for reducing size)

Fridlund answered 7/5, 2010 at 12:20 Comment(0)
P
10

By using the HALFTONE StretchBltMode, you will get smoother results than the normal stretchdraw. This will only work in windows 2000 and later

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;
Pomeranian answered 8/5, 2010 at 8:57 Comment(1)
@BrianFrost HALFTONE or STRETCH_HALFTONE is your best bet IMHO, here's some code code.google.com/p/delphigeist-delphi-stuff/source/browse/trunk/…Duodenary
F
9

I suppose you mean Stretched = True on a TImage, not on A TBitmap.

Unfortunately TImage has no resamplers built in, when it comes to resizing images in it. My recommendation would be to use Graphics32 as it supports a variety of resamplers (some are better for increasing size others for reducing size)

Fridlund answered 7/5, 2010 at 12:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.