If you’re on a Mac, I started using the command line utility screencapture via Applescript. It’s not mentioned in the man pages but there’s a -R switch that will capture a rectangle of the screen.
Applescript:
on run {x, y, w, h}
set str to (x & ", " & y & ", " & w & ", " & h) as string
do shell script ("screencapture -x -c -R '" & str & "'") as string
end run
calling from Xojo:
capture_screen_area(htmlviewer1.Left + window1.left, htmlviewer1.top + window1.top, htmlviewer1.Width, htmlviewer1.Height)
dim c as new Clipboard
temp_pic = c.Picture
c.close
My usage here is for an app only I will use so I’m sending the screen shot to the clipboard but you can just as easily send it to a temp file.
That won’t work… main reason I am not displaying the HTMLViewer to the user…
They have a rectangle they can drag around the screen … and I thought it would enhance the app if they could see a thumbnail of the URL they associated to it … but HTMLViewer has to be VISIBLE for screen capture to work…
Well, first you have to wait after LoadURL for the webviewer to actually load something, so make a pause.
Maybe check in DocumentComplete event.
Next you can take a screenshot.
But even better maybe to use our MBS Plugin functions to render the image as a picture object. And not just render the visible area, but the whole page.
Is there any news on this subject?
I want to use the htmlviewer.drawinto method to create a jpeg of the visible part of the webpage.
This may have been reportet as a bug four years ago.
Is this issue fixed now?
There are several workarounds in this forum, none of them is working properly on my mac with google maps.
[quote=389511:@Mario Schweda]Is there any news on this subject?
I want to use the htmlviewer.drawinto method to create a jpeg of the visible part of the webpage.
This may have been reportet as a bug four years ago.
Is this issue fixed now?
There are several workarounds in this forum, none of them is working properly on my mac with google maps.[/quote]
[quote=389549:@shao sean]Did you try HTMLViewer.DrawInto ? I don’t think anything has changed with it though… :-/
What version of Xojo?
32-bit, 64-bit, both?
What version of macOS?[/quote]
Both versions, Mac 10.13.4
I’m using wkhtmltoimage for some of my bash scripts and for perl.
Especially for xojo I didn’t want to use workarounds because the function is available in Xojo but not working.
At the end i’m ending up using a workaround where I create the image with googleapi.destination and then I’m creating a static map with googleapi.staticmaps.
I was looking into that. I guess this is not the right choice for my program.
Nice job with your xojo controls, by the way. I’m using the chart view controls all the time… it’s awesome.
This code works well for me in 10.11 thru 10.13. Requires MBS plugins.
Attributes( StructureAlignment = 1 ) Protected Structure NSRect
x as CGFloat
y as CGFloat
width as CGFloat
height as CGFloat
End Structure
Function GetScreenshot ( extends w as Window ) as Picture
#if TargetCocoa
dim captureRect as NSRect
captureRect.x = 0
captureRect.y = 0
captureRect.width = w.width
captureRect.height = w.height
dim nsv as NSViewMBS = w.TrueWindow.NSWindowMBS.contentView
declare function bitmapImageRepForCachingDisplayInRect lib kLibCocoa selector "bitmapImageRepForCachingDisplayInRect:" (obj_id as integer, rect as NSRect) as Ptr
dim rep as Ptr = bitmapImageRepForCachingDisplayInRect(nsv.Handle, captureRect)
declare sub cacheDisplayInRect lib kLibCocoa selector "cacheDisplayInRect:toBitmapImageRep:" (obj_id as Integer, rect as NSRect, rep as Ptr)
cacheDisplayInRect(nsv.handle,captureRect,rep) // WARNING: this may cause a Window.Paint event
declare function CGImage lib kLibAppKit selector "CGImage" ( NSBitmapImageRep as Ptr ) as Ptr
dim cgPtr as Ptr = CGImage( rep )
dim cgi as CGImageMBS = CGImageMBS.CreateImageWithHandle(integer(cgPtr))
dim pic as Picture = cgi.Picture
return pic
#endif
end function