2017-02-14 10 views
0

Je cherche un moyen d'ajouter une bordure solide avec Core Image. J'ai mis en application la caméra faite sur commande pour prendre des photos des documents de forme de rectangle. Maintenant, je reçois ce document quatre coordonnées, mais un problème pour dessiner la frontière sur CIImage. Aidez-moi, s'il vous plaît.dessiner une bordure autour de CIImage

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]; 
+0

Son son comme celui-ci http://stackoverflow.com/questions/11278647/add-solid- color-border-with-ciimage cliquez sur ce lien. –

Répondre

0

Vous pouvez utiliser ces méthodes:

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

appel à cette méthode:

UIImage *updatedIMG = [self addBorderToImage:[[UIImage alloc] initWithCIImage:overlay]] 
+0

Il se bloque sur CFRelease (cgimage); –