* 像素化到指定宽度
(sourceCanvas, targetWidth)
| 644 | * 像素化到指定宽度 |
| 645 | */ |
| 646 | pixelateToWidth(sourceCanvas, targetWidth) { |
| 647 | const aspectRatio = sourceCanvas.height / sourceCanvas.width; |
| 648 | const targetHeight = Math.round(targetWidth * aspectRatio); |
| 649 | |
| 650 | const targetCanvas = document.createElement('canvas'); |
| 651 | targetCanvas.width = targetWidth; |
| 652 | targetCanvas.height = targetHeight; |
| 653 | const targetCtx = targetCanvas.getContext('2d'); |
| 654 | |
| 655 | targetCtx.imageSmoothingEnabled = false; |
| 656 | targetCtx.drawImage(sourceCanvas, 0, 0, targetWidth, targetHeight); |
| 657 | |
| 658 | return targetCanvas; |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * 应用颜色量化 |
no outgoing calls
no test coverage detected