2012-07-01 21 views

Respuesta

1

Esto no es exactamente lo que preguntaste, pero podría ser mejor si sólo desea visualizar la imagen con un borde (en lugar de realmente dibujar una frontera sobre él) ...

Se puede utilizar CALayer a añadir bordes (y esquinas redondeadas, sombras, etc.) a cualquier UIView ...

// imgView is an instance of UIImageView, but this works with any UIView 
imgView.layer.borderWidth = 2.0f; 
imgView.layer.borderColor = [[UIColor blackColor] CGColor]; 

también es necesario #import <QuartzCore/QuartzCore.h> y enlazar con el marco QuartzCore para que esto funcione.

+0

Gracias jhabbott pero no me ayuda. Estoy tratando de modificar la imagen, no solo mostrar un borde en la parte superior. – frimoldi

2

Necesitamos tener la extensión de CIImage o el CGRect en el que queremos crear el borde sólido. Entonces, podemos dibujar un CIImage formando una línea continua en el área especificada, y repetir los pasos por 3 veces más para diferentes posiciones para dibujar un rectángulo sólido completo. A continuación está la pieza de código que dibujará una línea continua recta sobre el área especificada.

CIImage *overlay1 = [CIImage imageWithColor:[CIColor colorWithRed:255/255.f green:0/255.f blue:0/255.f alpha:1.00f]]; 
    overlay1 = [overlay1 imageByCroppingToRect:image.extent]; 
    overlay1 = [overlay1 imageByApplyingFilter:@"CIPerspectiveTransformWithExtent" withInputParameters:@{@"inputExtent":[CIVector vectorWithCGRect:image.extent],@"inputTopLeft":[CIVector vectorWithCGPoint:CGPointMake(topLeft.x - 5, topLeft.y + 5)],@"inputTopRight":[CIVector vectorWithCGPoint:CGPointMake(topRight.x + 5, topRight.y + 5)],@"inputBottomLeft":[CIVector vectorWithCGPoint:CGPointMake(topLeft.x - 5, topLeft.y)],@"inputBottomRight":[CIVector vectorWithCGPoint:CGPointMake(topRight.x + 5, topRight.y) ]}]; 
    overlay = [ overlay1 imageByCompositingOverImage:overlay]; 

He conservado el ancho de 5 píxeles. topLeft, topRight .... son los CGPoint respectivos para la posición. Para un rectángulo completo, también necesitará bottomLeft y bottomRight.

Superposición es el CIImage original.

+0

No estoy seguro de por qué necesita la transformación de perspectiva. ¿Por qué no simplemente recortar en la línea, como un rectángulo con ancho 5, 4 veces. – user1055568

Cuestiones relacionadas