0
我正在嘗試開發一個使用Core Graphics的繪圖應用程序。我想讓背景處於alpha狀態,而不是黑色。我嘗試使用所有不同類型的bitmapinfo類型,但沒有成功。 kCGImageAlphaPremultipliedLast也不起作用。任何人都知道如何解決此問題?CGbitmapcontext和alpha問題
- (BOOL) initContext:(CGSize)size {
int bitmapByteCount;
int bitmapBytesPerRow;
// Declare the number of bytes per row. Each pixel in the bitmap in this
// example is represented by 4 bytes; 8 bits each of red, green, blue, and
// alpha.
bitmapBytesPerRow = (size.width * 4);
bitmapByteCount = (bitmapBytesPerRow * size.height);
// Allocate memory for image data. This is the destination in memory
// where any drawing to the bitmap context will be rendered.
cacheBitmap = malloc(bitmapByteCount);
if (cacheBitmap == NULL){
return NO;
}
CGBitmapInfo bitmapInfo = kCGImageAlphaNoneSkipFirst;
cacheContext = CGBitmapContextCreate (cacheBitmap, size.width, size.height, 8, bitmapBytesPerRow, CGColorSpaceCreateDeviceRGB(), bitmapInfo);
CGContextSetRGBFillColor(cacheContext, 0, 0, 0, 0);
CGContextFillRect(cacheContext, (CGRect){CGPointZero, size});
return YES;
}
你在這裏的代碼沒有指定alpha通道(因此AlphaNone)我認爲你要找的可能是'kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrderDefault' –
另外,正如所寫的,我相信你正在泄漏由'CGColorSpaceCreateDeviceRGB()'分配的內存' –
你能解釋更多的泄漏內存嗎? – user3534757