ALAsset,将照片发送到包含其exif数据的Web服务 [英] ALAsset , send a photo to a web service including its exif data

查看:117
本文介绍了ALAsset,将照片发送到包含其exif数据的Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将相机胶卷中的照片发送到网络服务 - 包括其exif数据。
我使用ASIFormDataRequest - 所以我这样做:

I want to send a photo from the camera roll to a web services - including its exif data. Im using ASIFormDataRequest - so I do :

ASIFormDataRequest *request = [[ASIFormDataRequest alloc]initWithURL:url];

为了节省内存我直接想要发送文件:

To save memory I directly want to send the file:

[request addFile:localPath forKey:@"image"];

所以我需要资产的本地路径。
我想我无法获得资产的本地路径,因此我暂时将资产保存到文件中:

So i need the local path of the asset. I think I can not get the local path of an asset, so I temporarily save the asset to a file:

ALAsset* selectedAsset = [assets objectAtIndex:index];
CGImageRef imageRef = selectedAsset.defaultRepresentation.fullScreenImage;
UIImage* image = [UIImage imageWithCGImage:imageRef];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *cachesDirectory = [paths objectAtIndex:0];

NSData* imageData = UIImagePNGRepresentation(image);
NSString* filePath = [NSString stringWithFormat:@"%@/imageTemp.png",cachesDirectory];
[imageData writeToFile:filePath atomically:YES];

然后我用这条路径来做

[request addFile:localPath forKey:@"image"];

图像被发送到服务器 - 但没有我需要的exif数据。
除此之外,我认为必须有一个更明智的方法。

the image gets sent to the server - but without the exif data I need. Besides that, I think there must be a smarter way to do that.

tia

推荐答案

好吧 - 我想我想通了。诀窍是使用defaultRepresentaion的原始数据:

ok - i think i figured it out. The trick is to go with the defaultRepresentaion's raw data:

ALAsset* selectedAsset = [assets objectAtIndex:index];

int byteArraySize = selectedAsset.defaultRepresentation.size;

NSMutableData* rawData = [[NSMutableData alloc]initWithCapacity:byteArraySize];
void* bufferPointer = [rawData mutableBytes];

NSError* error=nil;
[selectedAsset.defaultRepresentation getBytes:bufferPointer fromOffset:0 length:byteArraySize error:&error];
if (error) {
    NSLog(@"%@",error);
}
rawData = [NSMutableData dataWithBytes:bufferPointer length:byteArraySize];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *cachesDirectory = [paths objectAtIndex:0];
NSString* filePath = [NSString stringWithFormat:@"%@/imageTemp.png",cachesDirectory];
[rawData writeToFile:filePath atomically:YES];

使用路径将图像发送到服务器后,服务器上的文件保留所有exif数据

After using the path to send the image to the server the file on the server keeps all the exif data

这篇关于ALAsset,将照片发送到包含其exif数据的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆