I am using the following code to create the ARGB8888 image. Is this the correct Image format for ARBG8888 or should I use a different format. This link is used to create the below Image FOrmat
guard let imageConversionToCGImage = img.cgImage,
let imageFormat = vImage_CGImageFormat(
bitsPerComponent: 8,
bitsPerPixel: 32,
colorSpace: CGColorSpaceCreateDeviceRGB(),
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.first.rawValue),
renderingIntent: .defaultIntent),
//Source buffer
let sourceBuffer = try? vImage_Buffer(cgImage: imageConversionToCGImage, format: imageFormat, flags: .noFlags),
//ARGBImage
let argb8888CGImage = try? sourceBuffer.createCGImage(format: imageFormat) else { return } ```
and I am getting the image data using the DataProvider.CFData for getting the data . Is this the right format or am I doing it wrong. What should I do to make it so I get the ARGB data.
When you pass a populated
vImage_CGImageFormatto that initializer, vImage will attempt to convert the source image to the specified format. For example, you could pass a grayscale image format such as:And the returned buffer will contain a grayscale representation of the source image regardless of the source image's format.
If you want to populate a buffer based on the format of the source image, pass an empty
vImage_CGImageFormatand use thevImageBuffer_InitWithCGImagefunction:On return,
imageFormatcontains the color space and bit depth of the source image, andsourceBuffercontains the image itself.Apple have just released the
vImage.PixelBufferthat provides a Swift friendly API to vImage. Take a look atinit(cgImage:cgImageFormat:pixelFormat:).Finally,
init(data:width:height:byteCountPerRow:pixelFormat:)shows an example of creating a vImage pixel buffer from a Core Graphics image's underlying data.