Hello Jürg!
I've solved creating raster patterns in my project by creating a symbol definition of image and placing many instances of it in a group with clipping mask and then rasterizing the Group. I understand that this is not the best way to make this operation. And if there are many symbols, then sometimes rasterizing takes very long. But not always. Sometimes it's fast, but after a number of times the same pattern was created, it takes for too long.
Wondering if you can give me some advice on how to solve this functionality more graceful. And maybe you can tell me why rasterizing the same amount of SymbolItems takes different time after several repeated rasterizations. Maybe this is somehow relatedto caching?
Here's my code:
var instances = [];
var size = symbolDef.item.bounds.size;//size of one piece of pattern
//calculate number of rows and coloumns for pattern
var nx = Math.ceil(bounds.width / size.width);
var ny = Math.ceil(bounds.height / size.height);
//first pattern center
var startPoint = bounds.topLeft + new Point(size.width / 2, size.height / 2);
var pattern = new Group();
//place symbolItems
for (var i = 0; i < nx; i++)
for (j = 0; j < ny; j++) {
var instance = symDef.place(startPoint + [size.width * i, size.height * j]);
pattern.addChild(instance);
}
//add Background if given
if (backgroundColor) {
var background = new Path.Rectangle(pattern.bounds);
background.style = {
fillColor: backgroundColor,
strokeColor: null,
strokeWidth: 0
};
pattern.insertChild(0, background);
}
var count = nx * ny;
var rasterPattern = pattern.rasterize(36);
pattern.removeChildren();//we need do this because otherwise symbolInstances are not being deleted
pattern.remove();
pattern = rasterPattern;
Thanks!
понедельник, 15 февраля 2016 г., 10:16:29 UTC+3 пользователь Jürg Lehni написал: