@@ -141,10 +141,11 @@ export function ScreenshotEditorFactoryv2({
141
141
const imageDimensions = getContainedSize ( measurementDiv , imageSource ) ;
142
142
143
143
resizeCanvas ( screenshotCanvas , imageDimensions ) ;
144
- const scale = screenshotCanvas . width / graywashCanvas . width ;
145
- setScaleFactor ( scale ) ;
146
144
resizeCanvas ( graywashCanvas , imageDimensions ) ;
147
145
146
+ const scale = graywashCanvas . clientWidth / imageBuffer . width ;
147
+ setScaleFactor ( scale ) ;
148
+
148
149
const screenshotContext = screenshotCanvas . getContext ( '2d' , { alpha : false } ) ;
149
150
if ( ! screenshotContext ) {
150
151
return ;
@@ -232,11 +233,7 @@ export function ScreenshotEditorFactoryv2({
232
233
ctx . fillRect ( 0 , 0 , graywashCanvas . width , graywashCanvas . height ) ;
233
234
}
234
235
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 ;
240
237
drawCommands . forEach ( rect => {
241
238
drawRect ( rect , ctx , scale ) ;
242
239
} ) ;
@@ -305,11 +302,7 @@ export function ScreenshotEditorFactoryv2({
305
302
// prevent drawing rect when clicking on the canvas (ie clicking delete)
306
303
if ( startX != endX && startY != endY ) {
307
304
// 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 ;
313
306
const rect = constructRect ( {
314
307
action,
315
308
startX : startX * scale ,
@@ -357,10 +350,10 @@ export function ScreenshotEditorFactoryv2({
357
350
class = "rect"
358
351
style = { {
359
352
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` ,
364
357
zIndex : 2 ,
365
358
} }
366
359
onMouseDown = { onDraw }
0 commit comments