0
這是下面的代碼:不知道我在做什麼錯,在這裏。它在我從NIB文件渲染圖層時用於工作。我試圖通過編程創建視圖來改變它。現在它渲染圖層,但沒有應用變形。renderInContext:不應用CALayer應用變換?
- (NSBitmapImageRep*)getCurrentFrame
{
CGContextRef bitmapContext = NULL;
CGColorSpaceRef colorSpace;
int bitmapByteCount;
int bitmapBytesPerRow;
int pixelsHigh = (int)[fixedWidthStringView bounds].size.height;
int pixelsWide = (int)[fixedWidthStringView bounds].size.width;
bitmapBytesPerRow = (pixelsWide * 4);
bitmapByteCount = (bitmapBytesPerRow * pixelsHigh);
colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
bitmapContext = CGBitmapContextCreate (NULL,
pixelsWide,
pixelsHigh,
8,
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedLast);
if (bitmapContext== NULL)
{
NSLog(@"Failed to create bitmapContext.");
return nil;
}
CGColorSpaceRelease(colorSpace);
[CATransaction setDisableActions:YES];
fixedWidthStringView.layer.transform = CATransform3DScale(fixedWidthStringView.layer.transform, .5, 1, 1);
[CATransaction commit];
[fixedWidthStringView.layer renderInContext:bitmapContext];
CGImageRef img = CGBitmapContextCreateImage(bitmapContext);
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:img];
CFRelease(img);
return bitmap;
}