2009-12-17 26 views

Respuesta

0

Tener un vistazo a this blog post, que proporciona código para iPhone OS 2.x & 3.0

+4

Esta publicación no ayuda. Se trata de que la imagen devuelta no se recorta correctamente de acuerdo con el rect cuadrado predeterminado en la vista de recorte y recorte incorporados, que se corrige en iOS 4.x. La pregunta, creo, es sobre la posibilidad de cambiar la relación de aspecto de la funcionalidad de vista previa/recorte. Anybodu tuvo suerte con eso? – esbenr

0

El diccionario en el método delegado devuelve todo eso:

NSString *const UIImagePickerControllerMediaType; 
NSString *const UIImagePickerControllerOriginalImage; 
NSString *const UIImagePickerControllerEditedImage; 
NSString *const UIImagePickerControllerCropRect; 
NSString *const UIImagePickerControllerMediaURL; 
NSString *const UIImagePickerControllerReferenceURL; 
NSString *const UIImagePickerControllerMediaMetadata; 

Asumo, que ha estado usando la EditedImage que es bastante inútil ... tal vez para algunas miniaturas ... de todos modos, el diccionario de información contiene datos de CropRect, lo único que tienes que hacer es recalcular los tamaños y recortar la imagen original tú mismo, usando por ejemplo esto: UIImage: Resize, then Crop

no he probado, este es sólo teoría :) ... pero en teoría, esto debería funcionar: D

0

Después de conseguir la imagen de la imagen selector y darle funcionalidad de cultivos como módulo diferente. De modo que el usuario puede seleccionar la parte de la imagen que desea recortar.

+0

Esto debería ser un comentario. No es una respuesta. – Praveenkumar

3

He hecho un proyecto similar. Tienes que usar un controlador de imagen. Encima de su controlador de imagen tiene que agregar otro controlador de imagen (solo porque esta es su área de recorte) arriba La parte vacía o sin llenar deImageController es donde tomará. (Lo que debe tener una imagen con 320x480 de tamaño y 320x385 vacío en ella.)

UIImage *image=theimageView.image; 
CGSize newSize; 
newSize.width=320; 
newSize.height=385; 
UIGraphicsBeginImageContext(newSize); 

//x=0 (because widhth : 320) y=0 (aboveImageController's empty part's start) 
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; 
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

CGImageRef imageRef = CGImageCreateWithImageInRect([newImage CGImage], rect); 
UIImage *img = [UIImage imageWithCGImage:imageRef]; 
CGImageRelease(imageRef); 
0

Se puede usar esta

UIImage *image1 = [self resizeImage:image width:320 height:385]; 


-(UIImage *)resizeImage:(UIImage *)image width:(int)wdth height:(int)hght{ 
    int w = image.size.width; 
    int h = image.size.height; 
    CGImageRef imageRef = [image CGImage]; 
    int width, height; 
    int destWidth = wdth; 
    int destHeight = hght; 
    if(w > h){ 
     width = destWidth; 
     height = h*destWidth/w; 
    } 
    else { 
     height = destHeight; 
     width = w*destHeight/h; 
    } 
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef bitmap; 
    bitmap = CGBitmapContextCreate(NULL, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedFirst); 

    if (image.imageOrientation == UIImageOrientationLeft) { 

     CGContextRotateCTM (bitmap, M_PI/2); 
     CGContextTranslateCTM (bitmap, 0, -height); 

    } else if (image.imageOrientation == UIImageOrientationRight) { 

     CGContextRotateCTM (bitmap, -M_PI/2); 
     CGContextTranslateCTM (bitmap, -width, 0); 

    } 
    else if (image.imageOrientation == UIImageOrientationUp) { 

    } else if (image.imageOrientation == UIImageOrientationDown) { 

     CGContextTranslateCTM (bitmap, width,height); 
     CGContextRotateCTM (bitmap, -M_PI); 
    } 

    CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef); 
    CGImageRef ref = CGBitmapContextCreateImage(bitmap); 
    UIImage *result = [UIImage imageWithCGImage:ref]; 
    CGContextRelease(bitmap); 
    CGImageRelease(ref); 

    return result; 

} 
2

Salida GKImagePicker

https://github.com/gekitz/GKImagePicker

El proyecto de ejemplo solo tiene iphone y solo admite álbum de fotos, pero pude ampliarlo fácilmente para incluir ipad y cámara. Lo he usado para hacer una vista de recorte personalizada que es un rectángulo redondeado de cualquier tamaño de dimensión.

+0

¿Cómo se deshizo de la pantalla original de Apple 'retomar/usar' cuando usaba GKImagePicker? Ahora mismo si tomo una foto con la cámara, primero se muestra esa pantalla, y si presiono 'usar', la versión de recorte de GKImagePicker de esa pantalla aparece inmediatamente después. Solo quiero la pantalla GKImagePicker. – Ramsel

+0

@RobertWagstaff, ¿cómo conseguiste que GKImagePicker trabajara con la cámara? ¿Todavía puede establecer el recorte de la misma manera o simplemente implementó sus propios métodos de cámara donde el código original no tenía ninguno? – DelightedD0D

+0

@ DelightedD0D sí, implementé mis propios métodos de cámara –

Cuestiones relacionadas