使用此功能裁剪图片后:
CGImageRef imageRef = CGImageCreateWithImageInRect([self.imageInput CGImage], rect);
UIImage *result = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
我把“结果”用于像这样的像素过程:
......
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
// Now your rawData contains the image data in the RGBA8888 pixel format.
int byteIndex = 0;
for (NSInteger i = 0 ; i < width * height; i++) {
int R = rawData[byteIndex];
int G = rawData[byteIndex + 1];
int B = rawData[byteIndex + 2];
int test = [self getValueof:0.3* R + 0.59* G + 0.11 * B inRange:0 to:255];
rawData[byteIndex] = (char)(test);
rawData[byteIndex + 1] = (char)(test);
rawData[byteIndex + 2] = (char)(test);
byteIndex += 4;
}
ctx = CGBitmapContextCreate(rawData,
CGImageGetWidth( imageRef ),
CGImageGetHeight( imageRef ),
8,
CGImageGetBytesPerRow( imageRef ),
CGImageGetColorSpace( imageRef ),
kCGImageAlphaPremultipliedLast );
imageRef = CGBitmapContextCreateImage (ctx);
UIImage* rawImage = [UIImage imageWithCGImage:imageRef];
CGContextRelease(ctx);
CGImageRelease(imageRef);
free(rawData);
我会崩溃吗?有知道的帮帮我吧。
更新崩溃报告::copy_read_only:vm_copy 失败:状态 1。
最佳答案
经过很长时间才找到解决此崩溃的方法。我有一个经验: - 在 iOS 上处理位图时:如果我们没有注意到图像的方向,可能会遇到一些奇怪的崩溃。
上面的崩溃:我很简单地修复了它:更改
UIImage *result = [UIImage imageWithCGImage:imageRef];
由
UIImage *result = [UIImage imageWithCGImage:imageRef scale:self.imageInput.scale orientation:self.imageInput.imageOrientation];
关于iphone - 裁剪图像后处理像素时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17690401/