.net - Save screenshot of WPF web browser Frame -
i have frame
element displaying html page in wpf application, , save screenshot of frame image.
with of google, have code:
size size = new size(previewframe.actualwidth, previewframe.actualheight); previewframe.measure(size); previewframe.arrange(new rect(size)); var renderbitmap = new rendertargetbitmap( (int)size.width, (int)size.height, 96d, 96d, pixelformats.pbgra32); renderbitmap.render(previewframe);
but ever blank image.
any thoughts on how fix code, and/or way capture web page image in app?
turns out gdi graphics
class has copyfromscreen
method works , captures frame
's contents:
var topleftcorner = previewframe.pointtoscreen(new system.windows.point(0, 0)); var topleftgdipoint = new system.drawing.point((int)topleftcorner.x, (int)topleftcorner.y); var size = new system.drawing.size((int)previewframe.actualwidth, (int)previewframe.actualheight); var screenshot = new bitmap((int)previewframe.actualwidth, (int)previewframe.actualheight); using (var graphics = graphics.fromimage(screenshot)) { graphics.copyfromscreen(topleftgdipoint, new system.drawing.point(), size, copypixeloperation.sourcecopy); } screenshot.save(@"c:\screenshot.png", imageformat.png);
Comments
Post a Comment