开发者

UIGraphicsGetCurrentContext Problem

开发者 https://www.devze.com 2023-02-20 11:31 出处:网络
I have a problem drawing objects passing this graphic context CGContextRef context = UIGraphicsGetCurrentContext();

I have a problem drawing objects passing this graphic context

CGContextRef context = UIGraphicsGetCurrentContext();

Here is the code I use to draw

- (void) draw: (CGContextRef) gc
{       
    CGFloat black[4] = {0.0f, 0.0f, 0.0f, 1.0f}; // R G B + Alpha
    CGPoint p [2];
    p[0].x = xStart ;
    p[0].y = yStart ;
    p[1].x = xEnd ;
    p[1].y = yEnd ;
    CGContextSetStrokeColor(gc, black); //Definie la couleur
    CGContextStrokeLineSegments(gc, p, 2 ) ;
}

Some object draw, other don't (very strange) and in the console I read:

    Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] &开发者_开发技巧lt;Error>: CGContextDrawImage: invalid context 0x0
Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] <Error>: CGContextSetStrokeColor: invalid context 0x0
Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] <Error>: CGContextStrokeLineSegments: invalid context 0x0
Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] <Error>: CGContextSetStrokeColor: invalid context 0x0
Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] <Error>: CGContextStrokeLineSegments: invalid context 0x0
Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] <Error>: CGContextSetStrokeColor: invalid context 0x0
Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] <Error>: CGContextStrokeLineSegments: invalid context 0x0
Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] <Error>: CGContextSetStrokeColor: invalid context 0x0
Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] <Error>: CGContextStrokeLineSegments: invalid context 0x0
Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] <Error>: CGContextSetStrokeColor: invalid context 0x0
Thu Mar 24 21:53:59 MacBook-Air-di-Michele-Giarratana.local IVBricker[381] <Error>: CGContextStrokeLineSegments: invalid context 0x0


So I can't speak to the invalid content errors because we'd need to see the rest of the code but it looks like the colour space could be incorrect (it's not RGB by default). Add this before you call stroke:

CGContextSetStrokeColorSpace(gc, CGColorSpaceCreateDeviceRGB());
0

精彩评论

暂无评论...
验证码 换一张
取 消