Frequently Asked Component Specific Questions

Options

Display all FAQ items

Search FAQ items:


Displaying items 1 to 1 of 1, page 1 of 1

<< previous next >>

TMS FMX WebOSMaps
Taking a screenshot in iOS

The code below generates a TBitmap from an instance of TTMSFMXWebOSMaps.

units
iOSApi.UIKit, MacApi.Dispatch, iOSApi.CoreGraphics, iOSApi.Foundation, MacApi.ObjectiveC,
FMX.Objects, FMX.StdCtrls;
rendering code
procedure UIGraphicsBeginImageContext(size: CGSize); cdecl; external libUIKit name _PU + 'UIGraphicsBeginImageContext';

implementation

function BitmapFromImage(AImage: UIImage): TBitmap;
var
  dt: NSData;
  ms: TMemoryStream;
begin
  Result := nil;
  if not Assigned(AImage) then
   Exit;

  dt := TNSData.Wrap(UIImagePNGRepresentation((AImage as ILocalObject).GetObjectID));
  if Assigned(dt) then
  begin
    Result := TBitmap.Create(0, 0);
    ms := TMemoryStream.Create;
    ms.Write(dt.bytes^, dt.length);
    Result.LoadFromStream(ms);
    ms.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  vw: UIView;
  img: UIImage;
  bmp: TBitmap;
begin
  vw := TUIView.Wrap(TMSFMXWebOSMaps1.NativeBrowser);
  UIGraphicsBeginImageContext(vw.bounds.size);
  vw.layer.renderInContext(UIGraphicsGetCurrentContext);
  img := TUIImage.Wrap(UIGraphicsGetImageFromCurrentImageContext);
  bmp := BitmapFromImage(img);
  Image1.Bitmap.Assign(bmp);
  bmp.free;
  UIGraphicsEndImageContext;
end;