Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace SpDPIResizeBitmap with a higher quality one. #122

Open
pyscripter opened this issue Oct 22, 2024 · 0 comments
Open

Replace SpDPIResizeBitmap with a higher quality one. #122

pyscripter opened this issue Oct 22, 2024 · 0 comments

Comments

@pyscripter
Copy link

The following code does a much better job at scaling bitmaps than SpDPIResizeBitmap.

procedure ResizeBitmap(Bitmap: TBitmap; const NewWidth, NewHeight: Integer);
var
  Factory: IWICImagingFactory;
  Scaler: IWICBitmapScaler;
  Source : TWICImage;
  IBitmap: IWICBitmap;
begin
  Source := TWICImage.Create;
  try
    Factory := TWICImage.ImagingFactory;
    Factory.CreateBitmapFromHBITMAP(Bitmap.Handle, Bitmap.Palette,
      WICBitmapUsePremultipliedAlpha, IBitmap);
    Factory.CreateBitmapScaler(Scaler);
    try
      Scaler.Initialize(IBitmap, NewWidth, NewHeight,
        WICBitmapInterpolationModeHighQualityCubic);
      Source.Handle := IWICBitmap(Scaler);
    finally
      Scaler := nil;
      Factory := nil;
    end;
    Bitmap.Assign(Source);
  finally
    Source.Free;
  end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant