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.

2
  • Would you be able to change that data format? Commented May 15, 2020 at 8:53
  • Yes, as long as I can set the individual pixels myself. Or more specific the color values of each pixel. Color representation is changeable, too Commented May 15, 2020 at 9:23

1 Answer 1

0

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

Apple has a good documentation to illustrate GPU programming.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.