No function getImageType() available?

Hi all,
why is there no getImageType() function available for ofImage class?
The exist a corresponding setImageType() and it got me thinking…

@synthnassizer, it’s true that it would make sense to have both a get and set function for the image type from an API consistency standpoint. Still, you can get the type of an image using the public property, type, of an ofImage:

int myImageType = myImage.type;
// myImageType will be equal to one of these constants:
//   OF_IMAGE_GRAYSCALE (aka a value of 0)
//   OF_IMAGE_COLOR (aka a value of 1)
//   OF_IMAGE_COLOR_ALPHA (aka a value of 2)

Well, yes.
but sometimes you might want to do

ofImage anImg( anotherImg.getPixelsRef() , anotherImg.width, anotherImg.height , anotherImg.type).

This last bit does not apply…

This would be the code that I think you are looking for:

ofImage img;
img.allocate(100, 100, OF_IMAGE_COLOR_ALPHA);
ofImage img2;
img2.allocate(img.width, img.height, (ofImageType)img.type);

type is an int, but the constructor is looking for a variable of type ofImageType. You just need to add in a cast to convert from int to ofImageType.

thank you!
I shall do typee casting then!

Hello Community!
I have a problem with casting the imageType

void myApp::setImage(ofImage& mother){

myImage.setFromPixels(mother.getPixels(), mother.width, mother.height,(ofImageType)mother.type);


any idea why I get this error?:

[ error ] ofPixels: allocate(): unknown image type, not allocating
[ error ] ofPixels: setFromPixels(): image type 3 not supported, not copying

Thank You!

@schnurbert, for whatever reason, your image (mother) has a type value of 3 which isn’t valid. My suspicion is that there is something funky happening with your mother image, because that setImage(...) function works for me. Can you share a larger chunk of your code?