Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何水平翻转画布图像?
我试过了
CanvasImage ci = graphics().createImage(width, height); ci.canvas().scale(-1.0F, 1.0F); ci.canvas().drawImage(image, 0, 0);
但它不起作用。
您不能简单地翻转比例,因为这将导致从 0 到 -width 的渲染,这将超出您正在绘制的图像的范围。
您需要按图像的宽度进行平移,以便从宽度渲染为 0:
CanvasImage ci = graphics().createImage(width, height); ci.canvas().translate(image.width(), 0); ci.canvas().scale(-1.0F, 1.0F); ci.canvas().drawImage(image, 0, 0);