0

I would like to generate a grid picture or bitmap or anything similar with raw pixel data in swift. Since the pixel location, image size etc. are not determined before the user opens the app or presses a refresh button I need a fast way to generate 2732x2048 or more individual pixels and display them on the screen.

First I did use UIGraphicsBeginImageContextWithOptions and drew each pixel with a 1x1 CGRect but this obviously did not scale well.

Afterwards I have used this approach: Pixel Array to UIImage in Swift But this is still kind of slow with the bigger screens.

Could something like this be done with MetalKit? I would assume that a lower api does render something like this way faster?

Or is there any better way to process something like this in-between MetalKit and CoreGraphics?


Some info regarding the structure of my data:

There is a struct with the pixel color data red, green, blue, alpha for each individual pixel stored as an Array and two image size variables: imageHeight and imageWidth.

tomaculum
  • 547
  • 4
  • 15

1 Answers1

0

The most performant way to do that is to use Metal Compute Function.

Apple has a good documentation to illustrate GPU programming.

Hamid Yusifli
  • 9,688
  • 2
  • 24
  • 48