【问题标题】:renderInContext: not rendering CALayer with transform applied?renderInContext:不渲染 CALayer 应用了变换?
【发布时间】:2012-06-22 21:25:20
【问题描述】:

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

}

【问题讨论】:

    标签: objective-c cocoa core-animation calayer


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多