在iOS 4.2上,当我使用UIImagePickerController让用户从照片库中选择一个图像时,这些是返回给我的字典键:
2011-03-02 13:15:59.518 xxx[15098:307] didFinishPickingMediaWithInfo:
info dictionary: {
UIImagePickerControllerMediaType = "public.image";
UIImagePickerControllerOriginalImage = "<UIImage: 0x3405d0>";
UIImagePickerControllerReferenceURL =
"assets-library://asset/asset.JPG?id=1000000050&ext=JPG";
}
Run Code Online (Sandbox Code Playgroud)
使用这些键中的一个或多个,如何获得包含图像元数据(例如曝光信息和GPS位置数据)的JPEG表示,以便我可以在某处上传并包含元数据(不会被剥离)?
我从Warren Burton看到的非常好的答案显示从iPhone中的ALAsset中检索到的URL显示图像?如何使用UIImagePickerControllerReferenceURL和ALAssetsLibrary assetForURL方法来获取ALAsset和ALAssetRepresentation.但是,我该怎样做才能获得包含所有元数据的JPEG?
或者是否有通过UIImage的机制?
这里的底线是我想获得包含在其中的元数据的JPEG ...
jpeg metadata uiimagepickercontroller uiimagejpegrepresentation
我有功能,它收到2个参数 - 图像和数字.下面的函数抛出EXC BAD ACCESS行"imgData = UIImageJPEGRepresentation(image,1.0);".我不知道为什么:-(任何想法?
- (void)saveImages:(UIImage*)image row:(int)row {
if (image != nil) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path1 = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat:@"%i.JPEG", row]];
NSString* path2 = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat:@"%is.JPEG", row]];
NSData* imgData;
imgData = UIImageJPEGRepresentation(image, 1.0);
[imgData writeToFile:path1 atomically:YES];
[self rotateIcon:image];
image = [self imageWithImage:image];
NSData* smalImgData = UIImageJPEGRepresentation(image, 1.0);
[smalImgData writeToFile:path2 atomically:YES];
}
}
Run Code Online (Sandbox Code Playgroud) cocoa-touch image exc-bad-access uikit uiimagejpegrepresentation
我想从UIImagepicker中选择一个图像,在相机胶卷中有PNG和JPG格式.
我需要将其转换为NSData.不过,我需要知道这是图像UIImageJPEGRepresentation还是UIImagePNGRepresentation,所以我可以将其转换.
UIImage *orginalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil];
NSData *orgData = UIImagePNGRepresentation(orginalImage);
Run Code Online (Sandbox Code Playgroud) iphone xcode uiimagejpegrepresentation ios uiimagepngrepresentation
我正在使用PhotoKit,并已实现过滤器用户可以应用于照片库中的照片.我目前正在获取图像,应用过滤器,将编辑后的版本作为a返回CIImage,然后我将其转换CIImage为NSData使用,UIImageJPEGRepresentation因此我可以将其写入磁盘.虽然这种方法效果很好,但当用户尝试编辑非常大(如30 MB)的照片时,可能需要花费30秒才能完成此操作,其中98%的时间用于UIImageJPEGRepresentation(从乐器获得的统计数据).
如果可能的话,我正在寻找一种更有效的方法将此编辑过的照片保存到磁盘而不会影响质量.
我理解UIImagePNGRepresentation可能会提高质量,但这比JPEG表示更慢.
这是我目前正在做的,在默认优先级线程(qos_class_utility)上:
func jpegRepresentationOfImage(image: CIImage) -> NSData {
let eaglContext = EAGLContext(API: .OpenGLES2)
let ciContext = CIContext(EAGLContext: eaglContext)
let outputImageRef = ciContext.createCGImage(image, fromRect: image.extent())
let uiImage = UIImage(CGImage: outputImageRef, scale: 1.0, orientation: UIImageOrientation.Up)
return UIImageJPEGRepresentation(uiImage, 0.9) //this takes upwards of 20-30 seconds with large photos!
}
//writing out to disk:
var error: NSError?
let success = jpegData.writeToURL(contentEditingOutput.renderedContentURL, options: NSDataWritingOptions.AtomicWrite, error: &error)
Run Code Online (Sandbox Code Playgroud) 在iPhone应用程序上,我需要通过邮件发送最大大小为300Ko的jpg(我不是没有mail.app可以拥有的最大大小,但这是另一个问题).要做到这一点,我试图降低质量,直到获得300Ko以下的图像.
为了获得质量好(compressionLevel)谁给我一个低于300Ko的jpg,我做了以下循环.它正在工作,但每次循环执行时,尽管"[tmpImage release];",我的jpg原始大小(700Ko)的内存增加了.
float compressionLevel = 1.0f;
int size = 300001;
while (size > 300000) {
UIImage *tmpImage =[[UIImage alloc] initWithContentsOfFile:[self fullDocumentsPathForTheFile:@"imageToAnalyse.jpg"]];
size = [UIImageJPEGRepresentation(tmpImage, compressionLevel) length];
[tmpImage release];
//In the following line, the 0.001f decrement is choose just in order test the increase of the memory
//compressionLevel = compressionLevel - 0.001f;
NSLog(@"Compression: %f",compressionLevel);
}
Run Code Online (Sandbox Code Playgroud)
关于我怎样才能解决它的原因,或者为什么会这样?谢谢
在我的iPhone应用程序,我存储图像到NSData由
UIImage *image =imageView.image;
NSData *myData = UIImagePNGRepresentation(image);
Run Code Online (Sandbox Code Playgroud)
但如何从" NSData"中取回"图像" ,我可以再次显示出来UIImageView.
请帮助和建议,谢谢.
我在使用UIImageJPEGRepresentation时收到内存警告,有什么方法可以避免这种情况吗?它不会崩溃应用程序,但我想尽可能避免它.它间歇性地不运行[[UIApplication sharedApplication] openURL:url];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
NSData *imageToUpload = UIImageJPEGRepresentation(image, 1.0);
// code that sends the image to a web service (omitted)
// on success from the service
// this sometime does not get run, I assume it has to do with the memory warning?
[[UIApplication sharedApplication] openURL:url];
}
Run Code Online (Sandbox Code Playgroud) 我想用UIImageJPEGRepresentation在iphone中添加图片,在下面的代码中我遗漏了一些我不知道如何添加的东西
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:gameObj.gameThumbnails]];
UIImage *myImage=[UIImage imageWithData:data];
imageView.image=UIImageJPEGRepresentation(myImage, 90);// I am missing something here
[elementView addSubview:imageView];
[imageView release];
/*gameObj.gameThumbnails is an url like http://static.gamesradar.com/images/mb/GamesRadar/us/Games/X/X-Men%20Arcade/Bulk%20Viewer/360%20PS3/2010-10-11/192.168.30.167-image36_bmp_jpgcopy--game_thumbnail.jpg
*/
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题
我使用imageWithData方法创建一个UIimage:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *data1 = UIImageJPEGRepresentation(chosenImage, 1);
NSData *data2 = UIImageJPEGRepresentation(chosenImage, 0.5);
NSLog(@"data1 = %lu;;;;;;;data2 = %lu",[data1 length],[data2 length]);
UIImage *nimg = [UIImage imageWithData:data2];
NSData *data30 = UIImageJPEGRepresentation(nimg, 1);
NSData *data31 = UIImageJPEGRepresentation(nimg, 0.8);
NSLog(@"data30 = %lu;;;;;;data31 = %lu;;;;;;",[data30 length],[data31 length]);
}
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
data1 = 1751828;;;;;;;data2 = 254737
data30 = 1368455;;;;;;data31 = 387174;;;;;;
Run Code Online (Sandbox Code Playgroud)
为什么data30比data2大得多?
我正在创建一个多部分图像数据上传请求。我通过 UIImageJPEGRepresentation 从 UIImage 获取 NSData 但是当我尝试将数据转换为字符串时我得到 nil 值
我已按照此链接将 NSData 转换为 NSString
将 UTF-8 编码的 NSData 转换为 NSString
这是我的代码:-
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableString *body = [NSMutableString string];
[body appendFormat:@"--%@\r\n", boundary];
int i =0;
for (UIImage *image in imagesArray) {
NSData *data = UIImageJPEGRepresentation(image, 1.0);
[body appendFormat:@"Content-Disposition:form-data; name=\"userfile[]\"; filename=\"image%d.jpeg\"\r\n",i];
[body appendFormat:@"Content-Type: image/*\r\n\r\n"];
NSString *str = [NSString stringWithUTF8String:[data bytes]]; //this variable should not be nil
[body appendFormat:@"%@",str];
if (error)
{
NSLog(@"%@", error);
}
i++; …Run Code Online (Sandbox Code Playgroud)