这是下面的代码:不确定我做错了什么,在这里。当我从 NIB 文件渲染图层时,它曾经工作过。我试图通过以编程方式创建视图来改变它。现在它渲染图层但没有应用任何变换。
- (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;
}