を解放する正しい方法私はこの機能を使用してunsigned char型のポインタを作成します。CとObjective-C - 私のアプリにunsigned char型ポインタ
- (unsigned char*)getRawData
{
// First get the image into your data buffer
CGImageRef image = [self CGImage];
NSUInteger width = CGImageGetWidth(image);
NSUInteger height = CGImageGetHeight(image);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc(height * width * 4);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextSetBlendMode(context, kCGBlendModeCopy);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, (CGFloat)width, (CGFloat)height), image);
CGContextRelease(context);
// Now your rawData contains the image data in the RGBA8888 pixel format.
return rawData;
}
そして、別のクラスでは、私はそうのようにそのポインタにプロパティを割り当てます:self.bitmapData = [image getRawData];
このプロセスではどこでmallocされたメモリを解放できますか? deallocでプロパティを解放しようとすると、exc_bad_accessエラーが発生します。私はここで基本的なCや目標-Cのコンセプトが欠けているように感じます。すべての助けに感謝します。
どのようにプロパティをfree'ingですか? – iandotkelly
各アロケータには、割り当てられたオブジェクトを解放するためのペア解除されたアロケータがあります。 ['malloc'](http://linux.die.net/man/3/malloc)のマニュアルページを見てください - しかしあなたの特定のプラットフォームに関連するドキュメントを見つけるのに最適です - 何を使うべきかを説明します;-) –
私は正しいように見えない無料(プロパティ)を試みたが、とにかくそれを行った。 –