关于图片:react图片缩放平移canvas实现

30次阅读

共计 765 个字符,预计需要花费 2 分钟才能阅读完成。

react 图片缩放、平移(position、transform 实现)上篇讲到了应用 position、transform 来实现图片的平移缩放。本篇将采纳 canvas 来实现看看。

canvas

HTML5 <canvas> 标签用于绘制图像(通过脚本,通常是 JavaScript)。不过,<canvas> 元素自身并没有绘制能力(它仅仅是图形的容器)– 您必须应用脚本来实现理论的绘图工作。

getContext():返回一个对象,该对象提供了用于在画布上绘图的办法和属性

getContext(contextId: "2d", options?: CanvasRenderingContext2DSettings): CanvasRenderingContext2D | null;
getContext(contextId: "bitmaprenderer", options?: ImageBitmapRenderingContextSettings): ImageBitmapRenderingContext | null;
getContext(contextId: "webgl", options?: WebGLContextAttributes): WebGLRenderingContext | null;
getContext(contextId: "webgl2", options?: WebGLContextAttributes): WebGL2RenderingContext | null;
getContext(contextId: string, options?: any): RenderingContext | null;

clearRect():在给定的矩形内革除指定的像素

clearRect(x: number, y: number, w: number, h: number): void;

正文完
 0