Extract path information from an black&white bitma

2019-03-22 03:22发布

问题:

It is not easy to draw a shape with Quartz 2D to depict an image as following. Is it possible to extract a CGPathRef information from a black&white bitmap image? The white part is actually transparent.

Edit:

What I want to achieve:

I want to set the physicsBody of a SKSpriteNode with the same shape of the image bottle.png

SKSpriteNode * myBottle = [SKSpriteNode spriteNodeWithImageNamed:@"bottle"];
.
.
.
myBottle.physicsBody = [SKPhysicsBody bodyWithEdgeChainFromPath:path];

Her path is a CGPathRef, I wanna to make it have the same shape with the image bottle.png

回答1:

Google potrace It's one of several open source libraries that do this. It also handily links to others.