Этот код выдает очень странный результат. Почему? Все, что я делаю, это копирую изображение.
NSData *data = [NSData dataWithContentsOfFile: @"/Users/Jojo/Desktop/k2.jpg"];
NSBitmapImageRep *image = [NSBitmapImageRep imageRepWithData: data];
assert(image.samplesPerPixel == 3);
assert(image.isPlanar == NO);
uint8_t *buffer = [image bitmapData];
NSBitmapImageRep *rtn = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:&buffer
pixelsWide:image.pixelsWide
pixelsHigh:image.pixelsHigh
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow: image.pixelsWide*3
bitsPerPixel: 8*3];
NSData *newJpg = [rtn representationUsingType:NSJPEGFileType properties:nil];
[newJpg writeToFile:@"/Users/Jojo/Desktop/and.jpg" atomically:YES];
Пример: