generated from gxc-solutions/gxc-template-repo
Support for render ImageBitmap
This commit is contained in:
parent
3c3b13e22f
commit
c0150f85fa
5 changed files with 40 additions and 19 deletions
|
|
@ -167,6 +167,18 @@ export class Artist {
|
|||
this._context.restore();
|
||||
}
|
||||
|
||||
drawImage2(source: ImageBitmap, position: IPoint, size: ISize) {
|
||||
this._context.save();
|
||||
const scaleY = size.height / source.height;
|
||||
const scaleX = size.width / source.width;
|
||||
|
||||
this._context.translate(position.x + size.width / 2, position.y + size.height / 2);
|
||||
this._context.scale(scaleY, scaleX);
|
||||
|
||||
this._context.drawImage(source, -source.width / 2, -source.height / 2);
|
||||
this._context.restore();
|
||||
}
|
||||
|
||||
drawPath(path: string) {
|
||||
const path2d = new Path2D(path);
|
||||
this._context.stroke(path2d);
|
||||
|
|
|
|||
|
|
@ -92,11 +92,20 @@ export class Canvas2DRenderer implements IRenderer {
|
|||
this._context.globalCompositeOperation = dn.blendMode as GlobalCompositeOperation;
|
||||
this._artist.setTransform(dn.transform);
|
||||
|
||||
this._artist.drawImage(
|
||||
dn.source,
|
||||
{ x: dn.rectangle.x, y: dn.rectangle.y },
|
||||
{ width: dn.rectangle.width, height: dn.rectangle.height },
|
||||
);
|
||||
if (dn.source instanceof HTMLImageElement) {
|
||||
this._artist.drawImage(
|
||||
dn.source,
|
||||
{ x: dn.rectangle.x, y: dn.rectangle.y },
|
||||
{ width: dn.rectangle.width, height: dn.rectangle.height },
|
||||
);
|
||||
} else if (dn.source instanceof ImageBitmap) {
|
||||
this._artist.drawImage2(
|
||||
dn.source,
|
||||
{ x: dn.rectangle.x, y: dn.rectangle.y },
|
||||
{ width: dn.rectangle.width, height: dn.rectangle.height },
|
||||
);
|
||||
}
|
||||
|
||||
this._context.restore();
|
||||
}
|
||||
if (isRectangleDrawObject(leaf)) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gxc-solutions/renderer-canvas-2d",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"main": "index.js",
|
||||
"author": "GXC Solutions",
|
||||
"publishConfig": {
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
"registry": "https://npm.gxc-solutions.ru"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@gxc-solutions/math": "^0.0.1",
|
||||
"@gxc-solutions/renderer-base": "^0.0.9"
|
||||
"@gxc-solutions/math": "^0.0.2",
|
||||
"@gxc-solutions/renderer-base": "^0.0.10"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue