I experimented a few ways to make the same work with Cocoa and
GNUstep.
So here is the result.
At the beginning I was doing this:
[ anImage lockFocus ];
// Draw...
[ anImage unlockFocus ];
data = [ anImage TIFFRepresentation ];
-> Works with Cocoa, should be working with GNUstep but current
implementation doesn't support it.
Then tried:
NSBitmapImageRep ir = [ [ NSBitmapImageRep alloc ]
initWithBitmapDataPlanes: ..... ];
[ anImage addRepresentation: ir ];
[ anImage lockFocusOnRepresentation: ir ];
// Draw
[ anImage unlockFocus ];
data = [ ir TIFFRepresentation ];
--> yields an empty/transparent image (i think because my bitmap was
supporting transparency)
WORKING CODE FOLLOWS:
[ anImage lockFocus ];
// Draw...
[ anImage unlockFocus ];
//...some code... but i think could be collapsed if needed within the
previous lockFocus/unlockFocus pair
[ anImage lockFocus ];
ir = [ [ NSBitmapImageRep alloc ] initWithFocusedViewRect:
NSMakeRect(
0.0, 0.0, imageWidth, imageHeight ) ];
[ anImage unlockFocus ];
data = [ ir TIFFRepresentation ];
So, I think, the most simple thing to do in order to get a working
NSImage -(NSData *)TIFFRepresentation is:
If there is already a bitmap rep available, then return its
TIFFRepresentation data.
If not, create one with the code above and add the representation
in the
rep set for the image, then return the TIFFRepresentation.
What do you thing about this?
I don't think this is the best way to go, but this should work.