相关疑难解决方法(0)

如何使用UIBezierPath创建UIImage

我写了一些代码来创建一个UIImage具有UIBezierPath,但没有奏效.有人可以帮我找出我的代码有什么问题.

-(UIImage*) drawTriangle{
    CGRect rect = CGRectMake(0.0, 0.0, 30.0, 30.0);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    UIGraphicsPushContext(context);
    UIBezierPath *bezier = [UIBezierPath bezierPathWithRect:rect];
    [bezier moveToPoint:CGPointMake(25, 5)];
    [bezier addLineToPoint:CGPointMake(5, 15)];
    [bezier addLineToPoint:CGPointMake(25, 25)];
    [bezier setLineWidth:3.0];
    [bezier setLineJoinStyle:kCGLineJoinBevel];
    [bezier stroke];
    CGContextAddPath(context, bezier.CGPath);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsPopContext();
    UIGraphicsEndImageContext();
    return image;
}
Run Code Online (Sandbox Code Playgroud)

uiimage ios uibezierpath

11
推荐指数
3
解决办法
2万
查看次数

IOS UIImage图像颠倒了

如果我绘制我的图像我修复了问题使用CGAffintrasform

CGAffineTransform myTr = CGAffineTransformMake(1, 0, 0, -1, 0, backImage.size.height);
CGContextConcatCTM(context, myTr);
[backImage drawInRect:CGRectMake(cbx, -cby, backImage.size.width, backImage.size.height)];
myTr = CGAffineTransformMake(1, 0, 0, -1, 0, backImage.size.height);
CGContextConcatCTM(context, myTr);
Run Code Online (Sandbox Code Playgroud)

当我想写文件我用这个

 NSData *imageData = UIImageJPEGRepresentation(backImage, 0);  
Run Code Online (Sandbox Code Playgroud)

然后图像颠倒了怎么样?

jpeg draw uiimage ios

7
推荐指数
1
解决办法
3736
查看次数

标签 统计

ios ×2

uiimage ×2

draw ×1

jpeg ×1

uibezierpath ×1