I get NSImage like that:
imageG = [[[NSImage alloc] initWithSize:NSMakeSize(imageN.size.width, imageN.size.height)] autorelease];
[imageG addRepresentation:[NSCIImageRep imageRepWithCIImage:result]];
And the result is really good. So there are no mistakes i think. And then I try to convert this image to NSData like that:
NSData *imgData = [imageG TIFFRepresentation];
And i am getting error:
Thread 1: EXC_BAD_ACCESS (code=13, adress=0x0)
at that line. Where is my mistake?
You need to
retainyour object as you create it, it appears it’s being reallocated by the time you ask it for its data reorientation.imageG = [[[[NSImage alloc] initWithSize:NSMakeSize(imageN.size.width, imageN.size.height)] retain] autorelease];Generally if you create an object from an initializer – not a factory method – you should retain and auto release it. The benefits of doing so, and other good tips on memory management can be found at: Why should a self-implemented getter retain and autorelease the returned object?
It’s also to handy to note that
BAD_ACCESSindicates a memory issue of some kind.