Skip to content

Instantly share code, notes, and snippets.

View AIOSYM's full-sized avatar

David Pich AIOSYM

  • Loglass Inc.
  • Tokyo, Japan
View GitHub Profile
@palmerc
palmerc / imageRoundtrip.swift
Last active April 15, 2024 03:35
Roundtrip a UIImage to its raw pixel values and back to an image again
import UIKit
import CoreGraphics
func imageFromPixelValues(pixelValues: [UInt8]?, width: Int, height: Int) -> CGImage?
{
var imageRef: CGImage?
if pixelValues != nil {
let imageDataPointer = UnsafeMutablePointer<UInt8>(pixelValues!)
let colorSpaceRef = CGColorSpaceCreateDeviceGray()