Reputation: 553
I want to do 2 things:
1) Load 8 bit grayscale image as 8 but grayscale image
2) Save it as 8 bit grayscale image
I try to load image to CIImage via [CIImage imageWithContentsOfURL:options]`. As I understand I can specify some options in item options. But I didn't find any information how to do it. In reference of CIImage I found only these pixel formats:
extern CIFormat kCIFormatARGB8;
extern CIFormat kCIFormatRGBA16;
extern CIFormat kCIFormatRGBAf;
extern CIFormat kCIFormatRGBAh;
What does it mean? I can't load and save 8 bit grayscale images via CIImage?
Upvotes: 2
Views: 1723
Reputation: 565
Saving a CIImage to a grayscale image format is as simple as this:
CGColorSpaceRef cs = CGColorSpaceCreateWithName(kCGColorSpaceGenericGrayGamma2_2);
NSData *outData = [ctx PNGRepresentationOfImage:input
format:kCIFormatL8
colorSpace:cs
options:@{}];
Upvotes: 0
Reputation: 26335
No, there's no format for 8 bit grayscale. What is it you're trying to do? There are other ways to create an image using 8-bit grayscale, but without more info, it's hard to tell you what to suggest.
If you are going to use CoreImage to manipulate it, you'll need to put it into one of the RGB formats mentioned above. But if you're not going to use CoreImage to manipulate it, you might be able to create an NSImage
(by creating an NSBitmapImageRep
) or a CGImage (see CGImageCreate()
) in the format you want.
Upvotes: 1