I'm trying to create a new image with a specific ColorType
(it does the same thing with ColorSpace
) and I have this error: no pixels defined in cache
.
I'm not trying to load/read an existing image. I'm not trying to save the image. I'm just trying to set a property of the object. I don't even understand why there would be an exception thrown here.
Here is the code that is failing:
MagickImage img = new();
img.ColorType = ColorType.GrayscaleAlpha;
Here is the exception that is thrown:
If I remove the line that is failing, everything works fine. But I want to create a Png image with only gray and alpha channel. Maybe I'm not doing that properly.
Thanks for your help!
CodePudding user response:
This exception is thrown because you cannot set the ColorType
when you did not load any pixel data. You will need to first Read
an image before you can set that property.