Recent

Author Topic: Resize graphic proportionally  (Read 1873 times)

vonskie

  • Full Member
  • ***
  • Posts: 184
Resize graphic proportionally
« on: February 09, 2018, 10:04:58 pm »
What am I doing wrong here?

If bmp.width =< then it works okay

If bmp.width > does not scale correctly

What am I doing wrong?

if (checkboxresize.Checked) then
        begin
           if bmp.Width > bmp.Height then
          begin
            bmp.ResampleFilter := rfBestQuality;
            BGRAReplace(bmp,
            // bmp.resample(width,height)
            bmp.Resample(screen.width,(screen.Width * bmp.Height) div bmp.Width) as TBGRABitmap);
           end
          else
          begin
           
            bmp.ResampleFilter := rfBestQuality;
            BGRAReplace(BMP,
            bmp.resample((screen.Height * bmp.Width) div bmp.Height,screen.height) as TBGRABitmap);
          end;

vonskie

  • Full Member
  • ***
  • Posts: 184
Re: Resize graphic proportionally
« Reply #1 on: February 10, 2018, 02:05:06 am »
Here is a way that works

if (resizechecked) then
                begin

                  ratioX := screen.width / bmp.Width;
                  ratioY := screen.Height / bmp.Height;
                  ratio := Min(ratioX, ratioY);

                  newWidth := trunc(bmp.Width * ratio);
                  newHeight := trunc(bmp.Height * ratio);

                  bmp.ResampleFilter := rfBestQuality;
                   BGRAReplace(BMP, bmp.resample(newwidth,newheight)  as
                      TBGRABitmap);

                end;     

 

TinyPortal © 2005-2018