anchor.diff:    end;
   
     //Restore saved center position
  -  if AKeepPosition then
  -  begin
  -    if ANewLeft = 0 then
  -    begin
  -      AScrollMaxX:= Max(ANewWidth - AWidth, 0);
  +  if bKeepPosition then
  +  begin
  +    if NewLeft = 0 then
  +    begin
  +      ScrollMaxX:= Max(NewWidth - CliWidth, 0);
         HorzScrollBar.Position:=
  -        Min(AScrollMaxX, Trunc(ACenterRatioX * ANewWidth) - AWidth div 2);
  +        Min(ScrollMaxX, Trunc(CenterRatioX * NewWidth) - CliWidth div 2);
       end
       else
         HorzScrollBar.Position:= 0;
   
  -    if ANewTop = 0 then
  -    begin
  -      AScrollMaxY:= Max(ANewHeight - AHeight, 0);
  +    if NewTop = 0 then
  +    begin
  +      ScrollMaxY:= Max(NewHeight - CliHeight, 0);
         VertScrollBar.Position:=
  -        Min(AScrollMaxY, Trunc(ACenterRatioY * ANewHeight) - AHeight div 2);
  +        Min(ScrollMaxY, Trunc(CenterRatioY * NewHeight) - CliHeight div 2);
       end
       else
         VertScrollBar.Position:= 0;
  
positive.code: 
    VertScrollBar.Visible:= not FImageFit;
    HorzScrollBar.Visible:= not FImageFit;
    AWidth:= Width-NScrollbarSize;
    AHeight:= Height-NScrollbarSize;
  
    //Save center position, need to restore it later
    ACenterRatioX:= 0;
    ACenterRatioY:= 0;
  
    if FImage.Width > 0 then
    begin
      if FImage.Left >= 0 then
        ACenterRatioX:= (AWidth div 2 - FImage.Left) / FImage.Width
      else
        ACenterRatioX:= (AWidth div 2 + HorzScrollBar.Position) / FImage.Width;
    end;
  
    if FImage.Height > 0 then
    begin
      if FImage.Top >= 0 then
        ACenterRatioY:= (AHeight div 2 - FImage.Top) / FImage.Height
      else
        ACenterRatioY:= (AHeight div 2 + VertScrollBar.Position) / FImage.Height;
    end;
  
    //Set controls params
    if not AKeepPosition then
    begin
      HorzScrollBar.Position:= 0;
      VertScrollBar.Position:= 0;
  
negative.code:     {
      //Note: code commented in as it causes wrong scaling sometimes.
      //If image is already fit, don't scale it:
      if (FImage.Width = CliWidth) and
        (FImage.Height = CliHeight) then
      begin
        NewWidth:= FImage.Width;
        NewHeight:= FImage.Height;
      end
      else
      }
      //Need to scale
      begin
        NewWidth:= FImageWidth;
        NewHeight:= FImageHeight;
  
        if FImageFitOnlyBig and
          (FImageWidth <= CliWidth) and (FImageHeight <= CliHeight) then
        begin
          FImageScale:= 100;
        end
        else
        begin
          if (CliWidth > 0) and (CliHeight > 0) and
            (FImageWidth > 0) and (FImageHeight > 0) then
          begin
            NRatio:= CliWidth / CliHeight;
            NImageRatio:= FImageWidth / FImageHeight;
            if ((NRatio >= NImageRatio) and (not FImageFitWidth)) or FImageFitHeight then
            begin
              //fit height
              if FImageFitOnlyBig and (CliHeight >= FImageHeight) then begin end
              else
              begin
                NewHeight:= CliHeight;
                NewWidth:= Trunc(NewHeight * NImageRatio);
                FImageScale:= CliHeight * 100 div FImageHeight;
              end;
            end
            else
            begin
              //fit width
              if FImageFitOnlyBig and (CliWidth >= FImageWidth) then begin end
              else
              begin
                NewWidth:= CliWidth;
                NewHeight:= Trunc(NewWidth / NImageRatio);
                FImageScale:= CliWidth * 100 div FImageWidth;
              end;
            end;
          end;
  