绘制到CGImageRef中 [英] Drawing into CGImageRef

查看:116
本文介绍了绘制到CGImageRef中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



使用什么上下文来创建一个空的CGImageRef并能够绘制它。
CGContextRef或CGBitmapContextRef?



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


(((int)rintf([[[UIScreen mainScreen] currentMode] size] .width / [

解决方案

  #define HIRESDEVICE [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;


//创建给定大小的位图图形上下文
//
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL,width * imageScale,height * imageScale,8,0,colorSpace,kCGImageAlphaPremultipliedLast);


//绘制...
//
CGContextSetRGBFillColor(上下文,(CGFloat)0.0,(CGFloat)0.0,(CGFloat)0.0,(CGFloat) 1.0);
// ...


//获取图片
//
CGImageRef cgImage = CGBitmapContextCreateImage(context);

CGColorSpaceRelease(colorSpace);
CGContextRelease(context);

返回cgImage;
}


I want to create a CGImageRef and draw points to it.

What context to use to create an empty CGImageRef and be able to draw onto it. CGContextRef or CGBitmapContextRef?

If you can provide code to create an empty CGImageRef image and draw to it I would appreciate.

解决方案

#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;
    }

这篇关于绘制到CGImageRef中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆