@@ -1361,8 +1361,26 @@ export class Canvas implements ICanvas {
1361
1361
mWidth : number ;
1362
1362
mHeight : number ;
1363
1363
mScale = 1 ;
1364
+ mIsBitmap = false ;
1364
1365
view : WeakRef < CanvasView > ;
1365
1366
1367
+ constructor ( imageOrWidth : ImageSource | UIImage | number , height ?: number ) {
1368
+ let isBitmap = true ;
1369
+
1370
+ if ( imageOrWidth instanceof ImageSource ) {
1371
+ this . mCgContext = this . _createContextFromImage ( imageOrWidth . ios ) ;
1372
+ } else if ( imageOrWidth instanceof UIImage ) {
1373
+ this . mCgContext = this . _createContextFromImage ( imageOrWidth ) ;
1374
+ } else if ( imageOrWidth > 0 && height > 0 ) {
1375
+ this . mCgContext = this . _createContext ( imageOrWidth , height ) ;
1376
+ } else {
1377
+ isBitmap = false ;
1378
+ }
1379
+
1380
+ this . mIsBitmap = isBitmap ;
1381
+ // CGContextFillRect(this._cgContext);
1382
+ }
1383
+
1366
1384
setBitmap ( image ) {
1367
1385
// if (image instanceof ImageSource) {
1368
1386
// this._bitmap = image.android;
@@ -1454,14 +1472,13 @@ export class Canvas implements ICanvas {
1454
1472
setMatrix ( matrix : Matrix ) : void {
1455
1473
// TODO: Find a better way to implement matrix set
1456
1474
const ctx = this . ctx ;
1475
+ const density = this . mIsBitmap ? 1 : Screen . mainScreen . scale ;
1457
1476
const currentMatrix = this . getMatrix ( ) ;
1458
1477
const invertedTransform = CGAffineTransformInvert ( currentMatrix . mTransform ) ;
1459
- // Screen scale is excluded because it causes problems for other cases (e.g. bitmaps)
1460
- // Android canvas scale has to be re-applied after setMatrix() call too so this is going to make iOS behavior similar
1461
- const flipTransform = CGAffineTransformMake ( 1 , 0 , 0 , - 1 , 0 , this . mHeight ) ;
1478
+ const scaleTransform = CGAffineTransformMake ( density , 0 , 0 , - density , 0 , density * this . mHeight ) ;
1462
1479
1463
1480
CGContextConcatCTM ( ctx , invertedTransform ) ;
1464
- CGContextConcatCTM ( ctx , flipTransform ) ;
1481
+ CGContextConcatCTM ( ctx , scaleTransform ) ;
1465
1482
CGContextConcatCTM ( ctx , matrix . mTransform ) ;
1466
1483
}
1467
1484
getMatrix ( ) : Matrix {
@@ -1766,16 +1783,6 @@ export class Canvas implements ICanvas {
1766
1783
getHeight ( ) {
1767
1784
return this . mHeight ;
1768
1785
}
1769
- constructor ( imageOrWidth : ImageSource | UIImage | number , height ?: number ) {
1770
- if ( imageOrWidth instanceof ImageSource ) {
1771
- this . mCgContext = this . _createContextFromImage ( imageOrWidth . ios ) ;
1772
- } else if ( imageOrWidth instanceof UIImage ) {
1773
- this . mCgContext = this . _createContextFromImage ( imageOrWidth ) ;
1774
- } else if ( imageOrWidth > 0 && height > 0 ) {
1775
- this . mCgContext = this . _createContext ( imageOrWidth , height ) ;
1776
- }
1777
- // CGContextFillRect(this._cgContext);
1778
- }
1779
1786
1780
1787
startApplyPaint ( paint ?: Paint , withFont = false ) {
1781
1788
this . save ( ) ;
0 commit comments