gpt4 book ai didi

iphone - 绘制到 CGImageRef 中

转载 作者:行者123 更新时间:2023-12-03 18:37:39 24 4
gpt4 key购买 nike

我想创建一个 CGImageRef 并绘制指向它的点。

使用什么上下文来创建空的 CGImageRef 并能够在其上进行绘制。CGContextRef 还是 CGBitmapContextRef?

如果您可以提供代码来创建空的 CGImageRef 图像并绘制它,我将不胜感激。

最佳答案

#define HIRESDEVICE (((int)rintf([[[UIScreen mainScreen] currentMode] size].width/[[UIScreen mainScreen] bounds].size.width )>1))


- (CGImageRef) blerg
{
CGFloat imageScale = (CGFloat)1.0;
CGFloat width = (CGFloat)180.0;
CGFloat height = (CGFloat)180.0;

if ( HIRESDEVICE )
{
imageScale = (CGFloat)2.0;
}

// Create a bitmap graphics context of the given size
//
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, width * imageScale, height * imageScale, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);


// Draw ...
//
CGContextSetRGBFillColor(context, (CGFloat)0.0, (CGFloat)0.0, (CGFloat)0.0, (CGFloat)1.0 );
// …


// Get your image
//
CGImageRef cgImage = CGBitmapContextCreateImage(context);

CGColorSpaceRelease(colorSpace);
CGContextRelease(context);

return cgImage;
}

关于iphone - 绘制到 CGImageRef 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4257043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com