Quiero mostrar metadatos de imagen usando ios. Meta datos como apertura, velocidad de apertura, compensación de exposición, ISO, longitud focal de la lente, etc. Así que por favor ayúdenme si alguien tiene idea.Cómo obtener metadatos de imagen en ios
Respuesta
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef) aUrl, NULL);
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef) theData, NULL);
NSDictionary* metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source,0,NULL);
Consulte el contenido del diccionario here.
Gracias Jonas Schnelli. Me ayuda mucho Gracias amigo. –
Por supuesto, debe mencionar que deberá agregar #import
Si usa ARC, divídalo como para evitar pérdida de memoria 'CFDictionaryRef dictRef = CGImageSourceCopyPropertiesAtIndex (fuente, 0, NULL); NSDictionary * metadata = (__bridge NSDictionary *) dictRef;
Aquí es código, para obtener los metadatos de una ruta de la imagen:
NSData *imagedata = [NSData dataWithContentsOfFile:imagePath];
CGImageSourceRef source = CGImageSourceCreateWithData((CFMutableDataRef)imagedata, NULL);
NSDictionary *metadata = [(NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source,0,NULL)autorelease];
O, si utiliza veloz 4.0:
var imagedata = Data(contentsOfFile: imagePath)
var source: CGImageSourceRef = CGImageSourceCreateWithData((imagedata as? CFMutableDataRef), nil)
var metadata = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [AnyHashable: Any]
cómo hacerlo en swift3 o swift4? –
var imagedata = Datos (contentsOfFile: imagePath) fuente var: CGImageSourceRef = CGImageSourceCreateWithData ((datadata como? CFMutableDataRef), nil) var metadata = CGImageSourceCopyPropertiesAtIndex (fuente, 0, nil) as? [AnyHashable: Any] –
Espero que te ayude –
Es necesario utilizar elementos de bibliotecas para leer los metadatos EXIF de la imagen .
#import <AssetsLibrary/AssetsLibrary.h>
Y a continuación, añadir siguiente código:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
__block NSMutableDictionary *imageMetadata = nil;
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
NSDictionary *metadata = asset.defaultRepresentation.metadata;
imageMetadata = [[NSMutableDictionary alloc] initWithDictionary:metadata];
NSLog(@"%@",imageMetadata.description);
}
failureBlock:^(NSError *error) {
}];
}
la esperanza que esto ayudará
No funciona, assetURL siempre es nulo – malex
Esto es lo que estoy usando para obtener el tamaño de la imagen:
+ (CGSize) sizeOfImage:(NSString *) fileName withPath: (NSURL *) fullDirectoryPath;
{
NSURL *imageNameWithPath = [NSURL URLWithString:fileName relativeToURL:fullDirectoryPath];
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef) imageNameWithPath, NULL);
if (!source) return CGSizeZero;
CFDictionaryRef dictRef = CGImageSourceCopyPropertiesAtIndex(source,0,NULL);
NSDictionary* metadata = (__bridge NSDictionary *)dictRef;
NSLog(@"metadata= %@", metadata);
CGSize result = CGSizeZero;
CGFloat width = [metadata[@"PixelWidth"] floatValue];
CGFloat height = [metadata[@"PixelHeight"] floatValue];
NSLog(@"width= %f, height= %f", width, height);
// The orientation in the metadata does *not* map to UIImageOrientation. Rather, see: https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGImageProperties_Reference/index.html#//apple_ref/doc/constant_group/Individual_Image_Properties
// This idea of orientation seems a little odd to me, but it seems it translates to even numbers need to be switched in width/height, odd numbers do not.
NSUInteger orientation = [metadata[@"Orientation"] integerValue];
switch (orientation) {
// Comments give "Location of the origin of the image"
case 1: // Top, left
case 3: // Bottom, right
case 5: // Left, top
case 7: // Right, bottom
result = CGSizeMake(width, height);
break;
case 2: // Top, right
case 4: // Bottom, left
case 6: // Right, top
case 8: // Left, bottom
result = CGSizeMake(height, width);
break;
default:
NSAssert(NO, @"Should not get to here!");
break;
}
CFRelease(source);
NSLog(@"size: %@, orientation: %d", NSStringFromCGSize(result), orientation);
return result;
}
/* Example meta data:
ColorModel = RGB;
Depth = 8;
Orientation = 6;
PixelHeight = 1936;
PixelWidth = 2592;
"{Exif}" = {
ColorSpace = 1;
PixelXDimension = 2592;
PixelYDimension = 1936;
};
"{JFIF}" = {
DensityUnit = 0;
JFIFVersion = (
1,
1
);
XDensity = 1;
YDensity = 1;
};
"{TIFF}" = {
Orientation = 6;
};
}
*/
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
if(referenceURL) {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:referenceURL resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *rep = [asset defaultRepresentation];
NSDictionary *metadata = rep.metadata;
NSLog(@"image data %@", metadata);
} failureBlock:^(NSError *error) {
// error handling
}];
}
Es mejor dar algunas explicaciones en su respuesta. – Envil
swift 4
static func imageDataProperties(_ imageData: Data) -> NSDictionary? {
if let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil)
{
if let dictionary = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) {
return dictionary
}
}
return nil
}
Respondiendo a mi propia pregunta. La forma en la memoria-eficaz y rápido para obtener una metadatos GPS es
let options = [kCGImageSourceShouldCache as String: kCFBooleanFalse]
if let data = NSData(contentsOfURL: url), imgSrc = CGImageSourceCreateWithData(data, options) {
let metadata = CGImageSourceCopyPropertiesAtIndex(imgSrc, 0, options) as Dictionary
let gpsData = metadata[kCGImagePropertyGPSDictionary] as? [String : AnyObject]
}
La segunda opción es
if let img = CIImage(contentsOfURL: url), metadata = img.properties(),
gpsData = metadata[kCGImagePropertyGPSDictionary] as? [String : AnyObject] { … }
se ve mejor en Swift, pero utiliza más memoria (probado a través de perfiles).
actualizado a iOS 11 con fotos marco
Objetivo - C:
#import <Photos/Photos.h>
- (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
PHAsset* asset = info[UIImagePickerControllerPHAsset];
[asset requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
CIImage *fullImage = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
NSLog(@"%@", fullImage.properties.description);
}];
[imagePicker dismissViewControllerAnimated:YES completion:nil];
}
También es necesario el permiso de la Biblioteca de fotografías Uso (NSPhotoLibraryUsageDescription) y entonces puede agregar el código siguiente para verlo hizo cargar o ver apareció
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
switch (status) {
case PHAuthorizationStatusAuthorized:
NSLog(@"PHAuthorizationStatusAuthorized");
break;
case PHAuthorizationStatusDenied:
NSLog(@"PHAuthorizationStatusDenied");
break;
case PHAuthorizationStatusNotDetermined:
NSLog(@"PHAuthorizationStatusNotDetermined");
break;
case PHAuthorizationStatusRestricted:
NSLog(@"PHAuthorizationStatusRestricted");
break;
}
}];
- 1. ¿Cómo obtener metadatos de una imagen?
- 2. Obtener metadatos de MPMoviePlayerController
- 3. Escribir metadatos de dpi en una imagen jpeg en Java
- 4. Obtener metadatos de DOI
- 5. ¿Cómo puedo agregar metadatos a una imagen?
- 6. Guardar metadatos CUSTOM en una imagen tomada de AVFoundation en iOS
- 7. iOS: cómo obtener las dimensiones de la imagen sin abrirlo
- 8. cómo obtener los metadatos de jsTree.
- 9. Obtener texto de la imagen en ios (procesamiento de imágenes)
- 10. WordPress obtener usuario por metadatos
- 11. ¿Cómo obtener los metadatos del libro?
- 12. ¿Cómo añado metadatos a una imagen en Matlab?
- 13. ¿Dónde almacena WordPress metadatos de imagen?
- 14. ¿Cómo enmascarar una imagen en IOS SDK?
- 15. Cómo recortar una imagen en iOS
- 16. ¿Cómo extraer metadatos de mp3?
- 17. Obtener metadatos de SHOUTcast usando IcyStreamMeta
- 18. ¿Cómo obtener metadatos de películas de IMDB usando Java?
- 19. Imagen UIButton personalizada iOS
- 20. Cómo escalar una imagen en iOS, suavizada pero no suave?
- 21. cómo seguir actualizaciones de metadatos en Python
- 22. Superposición de una imagen sobre otra imagen en iOS
- 23. iOS UIView imagen de fondo
- 24. ¿Cómo obtener el tamaño táctil en iOS?
- 25. Cómo obtener tiempo en iOS Programación
- 26. ¿Cómo obtener datos del acelerómetro en IOS?
- 27. WPF imagen deslizar para cambiar la imagen como en iOS
- 28. ¿Cómo obtener este patrón en iOS?
- 29. Lea los metadatos del archivo de imagen con javascript
- 30. ¿Cómo agregar imagen de firma digital a PDF en iOS?
¿qué quiere decir con los metadatos de la imagen (nombre, tamaño y algunos otros)? Por favor, elabore ... –