我想添加缩略图(或直接从CGImageSourceRef传递)到CGImageDestinationRef,这样当使用CGImageSourceRef打开结果图像时,我可以使用CGImageSourceCreatethumbnailAtIndex来检索原始缩略图.
NSDictionary* thumbOpts = [NSDictionary dictionaryWithObjectsAndKeys: (ID)kcfBooleanTrue,(ID)kCGImageSourceCreatethumbnailWithtransform,(ID)kcfBooleanFalse,(ID)kCGImageSourceCreatethumbnailFromImageIfAbsent,[NSNumber numberWithInt:128],(ID)kCGImageSourcethumbnailMaxPixelSize,nil];CGImageRef thumb = CGImageSourceCreatethumbnailAtIndex(iSource,(CFDictionaryRef)thumbOpts);
上面的代码返回存储它的图像的缩略图,但是当我通过CGImageDestinationRef传递图像时,缩略图会丢失.
有没有办法保留原始缩略图(或创建一个新缩略图)? CGImageProperties Reference似乎没有任何键存储缩略图的位置.
解决方法 我发现获取缩略图的一种方法是在设置字典中指定kCGImageSourceCreatethumbnailFromImageIfAbsent.如下指定字典
NSDictionary* thumbOpts = [NSDictionary dictionaryWithObjectsAndKeys: (ID)kcfBooleanTrue,(ID)kcfBooleanTrue,nil];
更新:为了将辅助(缩略图)图像添加到原始CGImageDestinationRef,在添加主图像后执行以下 *** 作
size_t thumbWIDth = 640;size_t thumbHeight = imageHeight / (imageWIDth / thumbWIDth);size_t thumbBytesPerRow = thumbWIDth * 4;size_t thumbTotalBytes = thumbBytesPerRow * thumbHeight;voID *thumbData = malloc(thumbTotalBytes);CGContextRef thumbContext = CGBitmapContextCreate(thumbData,thumbWIDth,thumbHeight,8,thumbBytesPerRow,CGcolorSpaceCreateDeviceRGB(),kCGImageAlphaNoneskipFirst);CGRect thumbRect = CGRectMake(0.f,0.f,thumbHeight);CGContextDrawImage(thumbContext,thumbRect,fullimage);CGImageRef thumbImage = CGBitmapContextCreateImage(thumbContext);CGContextRelease(thumbContext);CGImageDestinationAddImage(destination,thumbImage,nil);CGImageRelease(thumbImage);
然后,为了恢复缩略图,请执行以下 *** 作
CFURLRef imagefileURLRef = (__brIDge CFURLRef)url;NSDictionary* sourceOptions = @{(ID)kCGImageSourceShouldCache: (ID)kcfBooleanFalse,(ID)kCGImageSourceTypeIDentifIErHint: (ID)kUTTypeTIFF};CFDictionaryRef sourceOptionsRef = (__brIDge CFDictionaryRef)sourceOptions;CGImageSourceRef imageSource = CGImageSourceCreateWithURL(imagefileURLRef,sourceOptionsRef);CGImageRef thumb = CGImageSourceCreateImageAtIndex(imageSource,1,sourceOptionsRef);UIImage *thumbImage = [[UIImage alloc] initWithCGImage:thumb];CFRelease(imageSource);CGImageRelease(thumb);总结
以上是内存溢出为你收集整理的objective-c – 将缩略图添加/传递(exif)到CGImageDestinationRef全部内容,希望文章能够帮你解决objective-c – 将缩略图添加/传递(exif)到CGImageDestinationRef所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)