Post

Replies

Boosts

Views

Activity

Reply to QR Code Generator (CIFilter) colours for light/dark mode ?
You can use the QR code as a mask and blend it with a solid color to effectively colorize it. So you can, for example, create a black and a white version and use the register(...) method of UIImage to "bundle" them both into one dynamic image: let qrCode = filter.outputImage!.transformed(by: transform) // Use the QR code as a mask for blending with a color. // Note that we need to invert the code for that, so the actual code becomes white // and the background becomes black, because white = let color through, black = transparent. let maskFilter = CIFilter.blendWithMask() maskFilter.maskImage = qrCode.applyingFilter("CIColorInvert") // create a version of the code with black foreground... maskFilter.inputImage = CIImage(color: .black) let blackCIImage = maskFilter.outputImage! // ... and one with white foreground maskFilter.inputImage = CIImage(color: .white) let whiteCIImage = maskFilter.outputImage! // render both images let blackImage = context.createCGImage(blackCIImage, from: blackCIImage.extent).map(UIImage.init)! let whiteImage = context.createCGImage(whiteCIImage, from: whiteCIImage.extent).map(UIImage.init)! // use black version for light mode qrImage = blackImage // assign the white version to be used in dark mode qrImage.imageAsset?.register(whiteImage, with: UITraitCollection(userInterfaceStyle: .dark)) return qrImage
Mar ’22
Reply to OpenEXR conversion
I recommend using Core Image to read, write, and modify EXR images. Core Image can already natively open PNG and EXR files and write PNG data and files. However, there is no convenient way for writing EXR data of files. That's why we wrote extensions for doing exactly that. You can find them over at Github.
Feb ’22
Reply to Passing MTLTexture to Metal Core Image Kernel
You can simply initialize a CIImage with the texture and pass that to the kernel: let ciImage = CIImage(mtlTexture: texture) The documentation also mentions what you need to do to let Core Image render into a Metal texture. If you want to incorporate a Metal processing step into a Core Image pipeline instead, I recommend you check out CIImageProcessorKernel.
Jan ’22
Reply to Save bytes-edited image on specific photo album as-is
I'm not totally sure, but I think it's not possible to just add some random data to the end of an image file like this. Photos has its own database for storing the images and I guess they perform some kind of sanitizing/cleaning when adding new entries. You can add custom data to a PHAsset that is stored alongside the image using PHAdjustmentData, but this is meant for storing "a description of the edits made to an asset's photo, video, or Live Photo content, which allows your app to reconstruct or revert the effects of prior editing sessions." So you would be able to read this data back, but only in an app that understands it. It won't be accessible when you just export the image out of Photos as a JPEG, for instance. And the amount of data you can store this way is also limited. However, you might be able to store the data in the image's (EXIF) metadata somewhere. This seems to me the appropriate place.
Apr ’21