Raphael-GWT: fill image of a shape (Rect) appears offset. How to resolve this?

南笙酒味 提交于 2019-12-08 06:45:30

问题


I'm wondering about the behavior of {Shape}.attr("fill","url({image.path})").

when applying a fill image to a shape:

public class AppMapCanvas extends Raphael {

    public AppMapCanvas(int width, int height) {
        super(width, height);
        this.hCenter = width / 2;
        this.vCenter = height / 2;
        ...
        Rect rect = this.new Rect(hCenter, vCenter, 144, 40, 4);
        rect.attr("fill", "url('../images/app-module-1-bg.png')"); // <--
        ...
    }
}

The background image seem to teal accross the canvas behind the shape, thus gets weird positioning (an illustration snapshot is enclosed - i marked the original image borders in red).

This seem to resolve itself in the presence of an animation along a path (a mere path.M(0,0) is sufficiant).

How can i position the fill-image properly in the first place?


回答1:


The proper way to do this from what I can understand would be to use an SVG pattern declaration to specify the portion and position of the image you would want to use. Then you would use that pattern to fill the rectangle element. Unfortunately, the Raphael javascript library doesn't have support for patterns... so there's no direct way to use an image to fill a rectangle.



来源:https://stackoverflow.com/questions/4769538/raphael-gwt-fill-image-of-a-shape-rect-appears-offset-how-to-resolve-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!