8

En mi iPhone App estoy recogiendo la imagen del iPhone biblioteca de imágenes, así de la cámara del dispositivo, y yo estoy mostrando esa imagen en imageView.imagen de la tienda de iPhone imageview para presentar

Puedo almacenar mi imagen en la biblioteca de imágenes del iPhone.

Pero ahora quiero guardar mi imagen en algún directorio con el nombre específico, por lo que se puede utilizar esa imagen en mi solicitud y también quiero almacenarlo en el archivo de SQLite.

Respuesta

9

Hay un corto valoración crítica de esta aquí: http://iosdevelopertips.com/data-file-management/save-uiimage-object-as-a-png-or-jpeg-file.html

Aquí está el código en cuestión robada directamente de ese sitio:

// Create paths to output images 
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"]; 
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"]; 

// Write a UIImage to JPEG with minimum compression (best quality) 
// The value 'image' must be a UIImage object 
// The value '1.0' represents image compression quality as value from 0.0 to 1.0 
[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES]; 

// Write image to PNG 
[UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES]; 

almacenarla en una base de datos SQLite que tomaría el código que hace un objeto NSData (UIImageJPEGRepresentation o UIImagePNGRepresentation) y guárdelos en una columna BLOB.

+0

iphonesdkarticles.com está muerto y tenía un robots.txt que prohibía archive.org para rastrearlo. –

3
NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/ImageFileName.jpg"]; 
[UIImageJPEGRepresentation(yourUIImageView.image,1.0) writeToFile:path atomically:YES]; 

Documentación: UIImageJPEGRepresentation

Si usted está manejando PNG hay otro método llamado UIImagePNGRepresentation.

Cuestiones relacionadas