我有一种应用色调效果过滤器并创建CGBitmapContext的方法。每次用户点击过滤器的按钮时,都会增加内存,并且内存不会被ARC释放。它每次增加600KB。我已经做了一些研究,发现仪器分配,核心图形增加600KB上CGDataProviderWithCopyOfData。我怎样才能释放这个CGRaster数据?当应用过滤器时释放CGDataProviderWithCopyOfData
这里是方法:
-(UIImage *)modifyImageTintColor:(UIImage *)source imageRawData:(Byte *)rawData degree:(int)degree{
double PI = 3.14159;
double HALF_CIRCLE_DEGREE = 180;
double RANGE = 256;
int RY, GY, BY, RYY, GYY, BYY, R, G, B, Y;
double angle = (PI * (double)degree)/HALF_CIRCLE_DEGREE;
int S = (int)(RANGE * sin(angle));
int C = (int)(RANGE * cos(angle));
CGFloat r, g, b;
//apply sepia effect
int byteIndex = 0;
for(int i = 0; i < _imageWidth * _imageHeight; ++i){
r = rawData[byteIndex];
g = rawData[byteIndex + 1];
b = rawData[byteIndex + 2];
RY = (70 * r - 59 * g - 11 * b)/100;
GY = (-30 * r + 41 * g - 11 * b)/100;
BY = (-30 * r - 59 * g + 89 * b)/100;
Y = (30 * r + 59 * g + 11 * b)/100;
RYY = (S * BY + C * RY)/256;
BYY = (C * BY - S * RY)/256;
GYY = (-51 * RYY - 19 * BYY)/100;
R = Y + RYY;
R = (R < 0) ? 0 : ((R > 255) ? 255 : R);
G = Y + GYY;
G = (G < 0) ? 0 : ((G > 255) ? 255 : G);
B = Y + BYY;
B = (B < 0) ? 0 : ((B > 255) ? 255 : B);
rawData[byteIndex] = R;
rawData[byteIndex + 1] = G;
rawData[byteIndex + 2] = B;
byteIndex += 4;
}
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * _imageWidth;
NSUInteger bitsPerComponent = 8;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef imageRef;
CGContextRef ctx;
ctx = CGBitmapContextCreate(rawData,
_imageWidth,
_imageHeight,
bitsPerComponent,
bytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
imageRef = CGBitmapContextCreateImage(ctx);
UIImage *result = [UIImage imageWithCGImage:imageRef];
CGContextRelease(ctx);
CGColorSpaceRelease(colorSpace);
CFRelease(ctx);
return result;
}
有没有人有答案? – 2014-10-24 14:41:41