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 mCL
Saving contents of NSView to an image file or stream

var
  bounds: NSRect;
  rep: NSBitmapImageRep;
  data: NSData;
  ms: TMemoryStream;
begin
  TMSFMXNativeNSView1.View.lockFocus;
  bounds := TMSFMXNativeNSView1.View.bounds;
  rep := TNSBitmapImageRep.Wrap(TNSBitmapImageRep.Wrap(TNSBitmapImageRep.OCClass.alloc).initWithFocusedViewRect(bounds));
  TMSFMXNativeNSView1.View.unlockFocus;
  data := rep.representationUsingType(NSPNGFileType, nil);
  //save to file
  data.writeToFile(NSSTR(TPath.GetDocumentsPath + PathDelim + 'test.png'), False);
  //save to stream
  ms := TMemoryStream.Create;
  ms.Write(data.bytes, data.length);
  Image1.Bitmap.LoadFromStream(ms);
  ms.Free;
  rep.release;