0

这是下面的代码:不确定我做错了什么,在这里。当我从 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;

}
4

1 回答 1

0

自己修好了。事实证明,只要我将我的 NSView 添加到另一个 NSView 并渲染容器,它就可以工作。

于 2012-06-22T23:02:46.517 回答