From ff3c3a101524a681b78df195eddeb1f29e043a01 Mon Sep 17 00:00:00 2001 From: vy Date: Sun, 19 Feb 2023 10:32:02 +0300 Subject: [PATCH 1/2] https://github.com/Bunlong/react-screen-capture/issues/10 - Seems to break on all screens above 1080p - fixed --- src/ScreenCapture.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ScreenCapture.tsx b/src/ScreenCapture.tsx index c94df06..86034a0 100644 --- a/src/ScreenCapture.tsx +++ b/src/ScreenCapture.tsx @@ -132,8 +132,8 @@ export default class ScreenCapture extends Component { } } - cropWidth *= window.devicePixelRatio; - cropHeigth *= window.devicePixelRatio; + //cropWidth *= window.devicePixelRatio; + //cropHeigth *= window.devicePixelRatio; this.setState({ crossHairsTop: e.clientY, @@ -182,6 +182,11 @@ export default class ScreenCapture extends Component { html2canvas(body).then(canvas => { const croppedCanvas = document.createElement('canvas'); const croppedCanvasContext = croppedCanvas.getContext('2d'); + + const scaleCropPositionLeft = cropPositionLeft * window.devicePixelRatio; + const scaleCropPositionTop = cropPositionTop * window.devicePixelRatio; + const scaleCropWidth = cropWidth * window.devicePixelRatio; + const scaleCropHeigth = cropHeigth * window.devicePixelRatio; croppedCanvas.width = cropWidth; croppedCanvas.height = cropHeigth; @@ -189,10 +194,10 @@ export default class ScreenCapture extends Component { if (croppedCanvasContext) { croppedCanvasContext.drawImage( canvas, - cropPositionLeft, - cropPositionTop, - cropWidth, - cropHeigth, + scaleCropPositionLeft, + scaleCropPositionTop, + scaleCropWidth, + scaleCropHeigth, 0, 0, cropWidth, From 41b9435307db38dbdc0665fd623dd310b41b9068 Mon Sep 17 00:00:00 2001 From: vy Date: Wed, 22 Feb 2023 10:32:09 +0300 Subject: [PATCH 2/2] https://github.com/Bunlong/react-screen-capture/issues/10 - Seems to break on all screens above 1080p - fixed --- src/ScreenCapture.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ScreenCapture.tsx b/src/ScreenCapture.tsx index 86034a0..1717f88 100644 --- a/src/ScreenCapture.tsx +++ b/src/ScreenCapture.tsx @@ -188,8 +188,8 @@ export default class ScreenCapture extends Component { const scaleCropWidth = cropWidth * window.devicePixelRatio; const scaleCropHeigth = cropHeigth * window.devicePixelRatio; - croppedCanvas.width = cropWidth; - croppedCanvas.height = cropHeigth; + croppedCanvas.width = scaleCropWidth; + croppedCanvas.height = scaleCropHeigth; if (croppedCanvasContext) { croppedCanvasContext.drawImage( @@ -200,8 +200,8 @@ export default class ScreenCapture extends Component { scaleCropHeigth, 0, 0, - cropWidth, - cropHeigth, + scaleCropWidth, + scaleCropHeigth, ); }