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?
 
Sinisa VukCommented:
FMX will work on Android as is, GDI+ don't ... Streching is not a problem, just implement aspect ratio calculation and will work...
0
 
Sinisa VukCommented:
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
 
Allan_FernandesAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.