简体   繁体   English

如何与CGBitmapContextCreate和Retina一起使用renderInContext:

[英]How to use renderInContext: with CGBitmapContextCreate and Retina?

I have manually created a CGBitmapContext: 我已经手动创建了CGBitmapContext:

bitmapContext = CGBitmapContextCreate( myImageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big );

And drawing a layer to it: 并为其绘制一层:

[self.myView.layer renderInContext:bitmapContext];

However, on Retina my layer renders only at half the original size. 但是,在Retina上,我的图层仅渲染原始大小的一半。

Setting the contentScaleFactor property on the UIView doesn't change anything. UIView上设置contentScaleFactor属性不会更改任何内容。

What's the right way to do this? 什么是正确的方法?

Of course the answer came to me the minute I asked the question. 当然,在我问问题的那一刻,答案就出现了。 Simply do this: 只需执行以下操作:

float scale = self.myView.contentScaleFactor;

CGContextScaleCTM(context, scale, scale);

[self.myView.layer renderInContext:context];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM