@@ -141,10 +141,11 @@ export function ScreenshotEditorFactoryv2({
141141 const imageDimensions = getContainedSize ( measurementDiv , imageSource ) ;
142142
143143 resizeCanvas ( screenshotCanvas , imageDimensions ) ;
144- const scale = screenshotCanvas . width / graywashCanvas . width ;
145- setScaleFactor ( scale ) ;
146144 resizeCanvas ( graywashCanvas , imageDimensions ) ;
147145
146+ const scale = graywashCanvas . clientWidth / imageBuffer . width ;
147+ setScaleFactor ( scale ) ;
148+
148149 const screenshotContext = screenshotCanvas . getContext ( '2d' , { alpha : false } ) ;
149150 if ( ! screenshotContext ) {
150151 return ;
@@ -232,11 +233,7 @@ export function ScreenshotEditorFactoryv2({
232233 ctx . fillRect ( 0 , 0 , graywashCanvas . width , graywashCanvas . height ) ;
233234 }
234235
235- const measurementDiv = measurementRef . current ;
236- if ( ! measurementDiv ) {
237- return ;
238- }
239- const scale = measurementDiv . clientWidth / imageBuffer . width ;
236+ const scale = graywashCanvas . clientWidth / imageBuffer . width ;
240237 drawCommands . forEach ( rect => {
241238 drawRect ( rect , ctx , scale ) ;
242239 } ) ;
@@ -305,11 +302,7 @@ export function ScreenshotEditorFactoryv2({
305302 // prevent drawing rect when clicking on the canvas (ie clicking delete)
306303 if ( startX != endX && startY != endY ) {
307304 // scale to image buffer
308- const measurementDiv = measurementRef . current ;
309- if ( ! measurementDiv ) {
310- return ;
311- }
312- const scale = imageBuffer . width / measurementDiv . clientWidth ;
305+ const scale = imageBuffer . width / graywashCanvas . clientWidth ;
313306 const rect = constructRect ( {
314307 action,
315308 startX : startX * scale ,
@@ -357,10 +350,10 @@ export function ScreenshotEditorFactoryv2({
357350 class = "rect"
358351 style = { {
359352 position : 'absolute' ,
360- top : `${ rect . y } px` ,
361- left : `${ rect . x } px` ,
362- width : `${ rect . width } px` ,
363- height : `${ rect . height } px` ,
353+ top : `${ rect . y * scaleFactor } px` ,
354+ left : `${ rect . x * scaleFactor } px` ,
355+ width : `${ rect . width * scaleFactor } px` ,
356+ height : `${ rect . height * scaleFactor } px` ,
364357 zIndex : 2 ,
365358 } }
366359 onMouseDown = { onDraw }
0 commit comments