【问题标题】:Merge UIImage and UIBezierPath into 1 UIImage将 UIImage 和 UIBezierPath 合并为 1 个 UIImage
【发布时间】:2015-06-16 18:13:10
【问题描述】:

我有一个具有UIImageDrawView 作为子视图的视图。绘制视图响应触摸并创建一个UIBezierPath 用于在图像上绘制。当用户接受他们的更改时,我需要将基础UIImage 和任何UIBezierPath 创建到一个UIImage 中。

【问题讨论】:

    标签: uiimageview uiimage core-graphics uibezierpath


    【解决方案1】:

    UIBazierPath 设为DrawView 的公共属性,并在用户从DrawView 中绘图时不断更新它。当用户点击接受按钮时,使用以下代码在上下文中简单地创建 UIImageContextdrawsourceImagebezierPath。最后在resultImage 中获取上下文中绘制的任何内容。

    UIBezierPath *path = drawView.Path // Your Bezier Path in DrawView
    UIImage *sourceImage = sourceImageView.image; // Your Source Image from ImageView.
    UIImage *resultImage = nil;
    UIGraphicsBeginImageContext(sourceImage.size);
    [sourceImage drawInRect:(CGRect){CGPointZero, sourceImage.size}];
    [path stroke]; //Fill or Stroke path as you need.
    [path fill];
    
    resultImage = UIGraphicsGetImageFromCurrentImageContext(); //taking the merged result from context, in a new Image. This is your required image.
    
    UIGraphicsEndImageContext();
    
    //Use resultImage as you want.
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    相关资源
    最近更新 更多