FMX not understanding HBITMAP for image resizing

I am using below code successfully via VCL, but FMX does not recognise HBITMAP.
I want to use below code via FMX to resize Bitmaps.

procedure TForm9.ScaleBitmap(Source, Dest: TBitmap; OutWidth, OutHeight: integer);
var
  src, dst: TGPBitmap;
  g: TGPGraphics;
  h: HBITMAP;
begin
  src := TGPBitmap.Create(Source.Handle, 0);
  try
    dst := TGPBitmap.Create(OutWidth, OutHeight);
    try
      g := TGPGraphics.Create(dst);
      try
        g.SetInterpolationMode(InterpolationModeHighQuality);
        g.SetPixelOffsetMode(PixelOffsetModeHighQuality);
        g.SetSmoothingMode(SmoothingModeHighQuality);
        g.DrawImage(src, 0, 0, dst.GetWidth, dst.GetHeight);
      finally
        g.Free;
      end;
      dst.GetHBITMAP(0, h);
      Dest.Handle := h;
    finally
      dst.Free;
    end;
  finally
    src.Free;
  end;
end;

Open in new window

Allan_FernandesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sinisa VukSoftware architectCommented:
try something like this:
procedure FMXScaleBitmap(Source, Dest: TBitmap; OutWidth, OutHeight: integer);
begin
  Dest.SetSize(OutWidth, OutHeight);

  if Dest.Canvas.BeginScene then
  begin
    try
      Dest.Canvas.Clear(TAlphaColors.White);
      Dest.Canvas.DrawBitmap(Source, Source.BoundsF, RectF(0, 0, OutWidth, OutHeight), 1);
    finally
      Dest.Canvas.EndScene;
    end;
  end;
end;

Open in new window

0
Allan_FernandesAuthor Commented:
With due respect, your suggested method uses the Stretching method and it is not supposed to deliver good quality resizing.

for good quality it has been suggested to use GDI+ scaling.
You can alter result quality and speed specifying different interpolation, pixel offset and smoothing modes defined in GDIPAPI.

https://stackoverflow.com/questions/33608134/fast-way-to-resize-an-image-mixing-fmx-and-vcl-code
0
Sinisa VukSoftware architectCommented:
FMX will work on Android as is, GDI+ don't ... Streching is not a problem, just implement aspect ratio calculation and will work...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Allan_FernandesAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.