Results 1 to 5 of 5

Thread: Resizing a bitmap...

  1. #1

    Resizing a bitmap...

    Resizing a bitmap...

    Anyone know of a good way to resize a bitmap? I mean an algorithm that produces a smooth looking resized image, unlike stretch draw!

    Maybe if I get the 'average' pixel colour per block of pixels that I want to resize?? It doesn't have to look great, just better than stretchdraw!
    http://www.c5software.co.uk (site is being developed at the moment)

  2. #2

    Resizing a bitmap...

    Either GraphicsEx.pas by Mike Lischke or Graphics32 contains good resampling filters (like Lanczos3, Mitchell, etc). I can't remember what's in them, though, so have a look through the source code yourself.
    "All paid jobs absorb and degrade the mind."
    <br />-- Aristotle

  3. #3

    Resizing a bitmap...

    Thankyou

    Yet again I am in debt to you!
    http://www.c5software.co.uk (site is being developed at the moment)

  4. #4

    Resizing a bitmap...

    Yeah, I know I am replying to myself... But this may help someone else with the same question:-

    http://www.torry.net/vcl/graphics/bitmap/resample.zip
    http://www.c5software.co.uk (site is being developed at the moment)

  5. #5

    Resizing a bitmap...

    here's some code I wrote to shrink an image using pixel-averaging (smooth resultant image).
    Code:
    // shrink image by a given ratio
    function Shrink&#40;ARatio &#58; Real ; ABitmap &#58; TBitmap&#41; &#58; TBitmap;
    Var
      Lx, Ly &#58; integer;
      LyBox, LxBox &#58; integer;
      TR, TG, TB &#58; integer;
      avR, avG, avB &#58; integer;
      LRowIn, LRowOut &#58; pRGBTripleArray;
      LBoxCount &#58; integer;
      LRatio &#58; Real;
    begin
      LRatio &#58;= 1 / ARatio;
    
      Result &#58;= TBitmap.Create;
      Result.PixelFormat &#58;= pf24bit;
      Result.Width &#58;= trunc&#40;ABitmap.Width / LRatio&#41;;
      Result.Height &#58;= trunc&#40;ABitmap.Height / LRatio&#41;;
    
      for Ly &#58;= 0 to Result.Height-1 do begin
        LRowOut &#58;= Result.ScanLine&#91;Ly&#93;;
        for Lx &#58;= 0 to Result.Width-1 do begin
    
          TR &#58;= 0; TG &#58;= 0; TB &#58;= 0;
          LBoxCount &#58;= 0;
          for LyBox &#58;= trunc&#40;Ly*LRatio&#41; to trunc&#40;&#40;Ly+1&#41;*LRatio&#41; - 1 do begin
            LRowIn &#58;= ABitmap.ScanLine&#91;LyBox&#93;;
            for LxBox &#58;= trunc&#40;Lx*LRatio&#41; to trunc&#40;&#40;Lx+1&#41;*LRatio&#41; - 1 do begin
              TR &#58;= TR + LRowIn&#91;LxBox&#93;.rgbtRed;
              TG &#58;= TG + LRowIn&#91;LxBox&#93;.rgbtGreen;
              TB &#58;= TB + LRowIn&#91;LxBox&#93;.rgbtBlue;
              Inc&#40;LBoxCount&#41;;
            end;
          end;
    
          avR &#58;= TR div LBoxCount;
          avG &#58;= TG div LBoxCount;
          avB &#58;= TB div LBoxCount;
          LRowOut&#91;Lx&#93;.rgbtBlue &#58;= avB;
          LRowOut&#91;Lx&#93;.rgbtGreen &#58;= avG;
          LRowOut&#91;Lx&#93;.rgbtRed &#58;= avR;
        end;
      end;
    
      ABitmap.Free;
    end;
    Hope it helps

    Peter

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •