[swift-users] How do I turn an array into a bitmap image?

Jens Alfke jens at mooseyard.com
Wed Mar 15 13:43:33 CDT 2017


> On Mar 15, 2017, at 11:07 AM, Nevin Brackett-Rozinsky via swift-users <swift-users at swift.org> wrote:
> 
> Ideally I’d like to create the bitmap image without having to allocate a second buffer. The sole purpose of the Float array is for creating this image, so I’d like to directly use its bytes as the pixels data. I expect this will involve some Unsafe[…] APIs in Swift, though I don’t know exactly how.

AFAIK there aren’t any pixmap formats that use floats. If you want to produce ARGB pixels, then emit your data in that format, i.e. as a [UInt8]. No unsafe stuff needed.

> And yes, I am on an Apple platform. Despite reading boatloads of Core Graphics documentation, I still can’t make heads or tails out of how to turn a pre-existing array into the backing data for a bitmap image. This part is only Swift-related in the sense that I am trying to do it in Swift, so if there’s a better place to ask/learn about it I’d appreciate being pointed there.

Either Apple’s developer forums, or the cocoa-dev mailing list hosted at http://lists.apple.com <http://lists.apple.com/>.

—Jens

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170315/77e14ff6/attachment.html>


More information about the swift-users mailing list