« first day 

Rob
2:32 PM
@Keith – You asked:
> One last issue I have a function that returns a Swift Image (returning images in my resources or SF Symbols. Is there a way to use that function instead?
First, an Image is a View. That would be a weird way to get the underlying asset. (It would be like trying to extract a table of data from a List object.) Second, the fundamental issue is that you need to fetch a CGImage, and Image offers no such capability.
You asked:
> In my case I'd rather the function silently fail when it can't find something or possibly just write out an error.
Then rather than try, you would try?.
… as shown in my ContentView example.
Or do-try-catch.
Or you can modify my code sample to return optional and then return nil rather than throw errors.
You asked:
> For the record, I'd rather pull the paths directly from the SF Symbols and drop those paths into my document but it appears that Swift doesn't have a way to do that.
Correct, it does not. There are third party libraries like SVGKit that extract paths from SVG files (and you can get SVG assets from SF Symbols. There might be other ways, too. But iOS offers no such capability.
You also asked:
> Coordinate system seams to be different then Swift Paths (objects ended up off screen). The imagines draw a few pixels down and to the right not sure why that happens.
First, if this was in iOS, one of my updates to my answer, I had a mistake in the withBackground(_:) implementation:
 
Rob
2:59 PM
Bottom line, images have a “scale” (where a size of 100×100 and a scale of 3 means that it really is 300×300px, behind the scenes). But cgImage doesn’t know for “scale”, so it just returns that underly 300×300 bitmaps. That is one common source of confusion.
The other issue is that the VNDetectContoursRequest returns a “normalized” path that has values between 0 and 1 and is, effectively, upside down (which is why we apply that CGAffineTransform).
Either one of those steps could have introduced your path going “off screen”.
I can’t tell on the basis of your comment.
Maybe post a separate question on that. Or post the code here in this chat (making sure to hit that “fixed font” button before hitting “send”; lol).
 
 
4 hours later…
Rob
7:15 PM
@Keith – I played around with this a little (re the path not getting scaled correctly), and so I have updated the code in my question to allow you to pass the image size to the path generator.
 

« first day