Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在图像周围绘制边框_Ios_Objective C_Core Image_Ciimage - Fatal编程技术网

Ios 在图像周围绘制边框

Ios 在图像周围绘制边框,ios,objective-c,core-image,ciimage,Ios,Objective C,Core Image,Ciimage,我正在寻找一种方法来添加一个核心图像固体边界。我已经实现了定制相机拍摄矩形文件。现在我得到了文件的四个坐标,但问题是在图像上画边界。请帮帮我 CIImage *overlay = [CIImage imageWithColor:[CIColor colorWithRed:0 green:1 blue:0 alpha:0.6]]; overlay = [overlay imageByCroppingToRect:image.extent]; overlay = [overlay imageByA

我正在寻找一种方法来添加一个核心图像固体边界。我已经实现了定制相机拍摄矩形文件。现在我得到了文件的四个坐标,但问题是在图像上画边界。请帮帮我

 CIImage *overlay = [CIImage imageWithColor:[CIColor colorWithRed:0 green:1 blue:0 alpha:0.6]];
overlay = [overlay imageByCroppingToRect:image.extent];
overlay = [overlay imageByApplyingFilter:@"CIPerspectiveTransformWithExtent" withInputParameters:@{@"inputExtent":[CIVector vectorWithCGRect:image.extent],@"inputTopLeft":[CIVector vectorWithCGPoint:topLeft],@"inputTopRight":[CIVector vectorWithCGPoint:topRight],@"inputBottomLeft":[CIVector vectorWithCGPoint:bottomLeft],@"inputBottomRight":[CIVector vectorWithCGPoint:bottomRight]}];

return [overlay imageByCompositingOverImage:image];

您可以使用以下方法:

- (UIImage *)addBorderToImage:(UIImage *)image {
    CGImageRef bgimage = [image CGImage];
    float width = CGImageGetWidth(bgimage);
    float height = CGImageGetHeight(bgimage);

        // Create a temporary texture data buffer
    void *data = malloc(width * height * 4);

    // Draw image to buffer
    CGContextRef ctx = CGBitmapContextCreate(data,
                                                 width,
                                                 height,
                                                 8,
                                                 width * 4,
                                                 CGImageGetColorSpace(image.CGImage),
                                                 kCGImageAlphaPremultipliedLast);
    CGContextDrawImage(ctx, CGRectMake(0, 0, (CGFloat)width, (CGFloat)height), bgimage);

    //Set the stroke (pen) color
    CGContextSetStrokeColorWithColor(ctx, [UIColor greenColor].CGColor);

    //Set the width of the pen mark
    CGFloat borderWidth = (float)width*0.05;
    CGContextSetLineWidth(ctx, borderWidth);

    //Start at 0,0 and draw a square
    CGContextMoveToPoint(ctx, 0.0, 0.0);    
    CGContextAddLineToPoint(ctx, 0.0, height);
    CGContextAddLineToPoint(ctx, width, height);
    CGContextAddLineToPoint(ctx, width, 0.0);
    CGContextAddLineToPoint(ctx, 0.0, 0.0);

    //Draw it
    CGContextStrokePath(ctx);

        // write it to a new image
    CGImageRef cgimage = CGBitmapContextCreateImage(ctx);
    UIImage *newImage = [UIImage imageWithCGImage:cgimage];
    CFRelease(cgimage);
    CGContextRelease(ctx);

        // auto-released
    return newImage;
}
调用此方法:

UIImage *updatedIMG = [self addBorderToImage:[[UIImage alloc] initWithCIImage:overlay]]
它听起来像是点击这个链接。它在CFRelease(cgimage)上崩溃;