- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 CGImageSourceCreateThumbnailAtIndex
有效地创建图像的调整大小版本。我有一些现有代码可以使用磁盘中的图像执行此操作,现在我正在尝试使用来自 ALAssetsLibrary
的图像。 .
这是我的代码:
ALAsset *asset;
ALAssetRepresentation *representation = [asset defaultRepresentation];
CGImageRef imageRef = [representation fullResolutionImage];
CGDataProviderRef provider = CGImageGetDataProvider(imageRef);
CGImageSourceRef sourceRef = CGImageSourceCreateWithDataProvider(provider, NULL);
NSDictionary *resizeOptions = @{
kCGImageSourceCreateThumbnailWithTransform : @YES,
kCGImageSourceCreateThumbnailFromImageAlways : @YES,
kCGImageSourceThumbnailMaxPixelSize : @(2100)
};
CGImageRef resizedImage = CGImageSourceCreateThumbnailAtIndex(source, 0, resizeOptions);
resizedImage
为空,并且
CGImageSourceGetCount(sourceRef)
返回 0。不过,数据提供程序中确实有相当多的数据,而且这些数据似乎是有效的图像数据。
ALAsset
来自 iPhone 4S 相机胶卷。
CGImageSourceCreateWithDataProvider()
创建一个包含 0 个图像的图像源?
最佳答案
CGImageSource 用于反序列化序列化图像,例如 JPEG、PNG 等。CGImageGetDataProvider
返回(提供者)图像的原始像素数据。它不会以某种外部格式返回序列化字节。 CGImageSource 无法知道任何给定的原始像素数据所在的像素格式(颜色空间、每组件位、alpha 布局等)。
您可以尝试获取 Assets 代表的 URL 并将其提供给 CGImageSourceCreateWithURL
.如果这不起作用(例如,不是文件 URL),则必须通过 CGImageDestination 运行图像,并在放置输出的任何位置创建 CGImageSource。
(要尝试的另一件事是查看代表的 filename
是否实际上是完整路径,Cocoa 经常误用该术语的方式。但您可能不应该指望这一点。)
关于core-graphics - 如何从 ALAssetRepresentation 创建有效的 CGImageSourceRef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17331756/
我正在使用以下内容从 ALAssetRepresentation 创建一个 NSData 对象,以导出图像文件并从中创建一个 md5 哈希: - (NSUInteger)getBytes:(uint8
我有一个 ALAssetRepresentation 问题。有一个表格以高分辨率显示图库图像。 fullScreenImage 方法花费太多时间,并且表格运行缓慢。如何实现更快的加载?例如,图库图像加
我有一些代码包装了一个 ALAsset 对象,该对象是从枚举 ALAssetLibrary 中的 Assets 中检索到的。我收到有关用户遇到崩溃的报告,其中部分包装器对象向其包含的 ALAsset
我的主要问题是我需要获取 ALAsset 对象的缩略图。 我尝试了很多解决方案并搜索了数天的堆栈溢出,由于这些限制,我发现的所有解决方案都不适合我: 我无法使用默认缩略图,因为它太小了; 我无法使用全
我正在上传相机胶卷中的视频和图像。上传完成后,我得到 32 字节的内存泄漏。仪器显示泄漏在下方 NSUInteger readStatus = [rep getBytes:buffer from
我正在编写一个多线程应用程序,它需要在后台从 ALAssetsLibrary 上传照片。所以我有一个 NSOperation 子类,它通过 Assets 的 URL 找到适当的 ALAsset 并将图
小问题:保证 ALAssetRepresentation URL(其“url”属性)指向同一 Assets 多长时间? documentation describes it as 'persisten
当我尝试访问照片流中的图片时,有时 [asset defaultRepresentation] 方法返回 nil。 根据文档,如果 Assets 在本地(尚)不可用,则可能会发生这种情况。 This
我正在尝试使用 CGImageSourceCreateThumbnailAtIndex有效地创建图像的调整大小版本。我有一些现有代码可以使用磁盘中的图像执行此操作,现在我正在尝试使用来自 ALAsse
我有一个返回 ALAsset 数据的方法。我为一个又一个 Assets 调用此方法,以从它们获取 NSData 并将其上传到服务器。每 4 或 5 次调用后,代码就会卡在下面的 rep.size 调用
这是我在 UITableViewDataSource View Controller 中的方法 - (UITableViewCell *)tableView:(UITableView *)tableV
我正在从我的 UITableView 中的 Assets 加载图像,我注意到我遇到了与从 defaultAssetRepresentation.fullResolutionImage.CGImage.
给定一个 ALAssetRepresentation,是否有可能得到它的全分辨率修饰图像? 如果我使用 fullResolutionImage 方法,我会得到全分辨率图像,但未以任何方式调整。 如果我
我正在尝试使用 fullScreenImage 方法从 ALAssetRepresentation 获取正确旋转的 UIImage。我有几张以不同设备方向拍摄的测试照片;照片在照片应用程序中正确显示。
我正在使用 ALAssetLibrary 从我的相机胶卷中获取我正在制作的自定义 View 的图像。这样做非常简单: library.enumerateGroupsWithTypes(ALAssets
我目前正在使用以下代码从 iOS 应用中的 ALAsset 获取 UIImage。 ALAssetRepresentation *rep = [self.asset defaultRepresenta
当用户在 iOS 的内置 Photos.app 中对照片进行一些更改(裁剪、消除红眼等)时,这些更改不会应用到 fullResolutionImage 由相应的 ALAssetRepresentati
在我的应用程序(在 iOS 4 下运行)中,我收集了通过 选择的图片UIImagePickerController .不幸的是,升级到 iOS 5 后我遇到了一个奇怪的问题。 简而言之,我存储 ALA
我注意到,对于图像,字典 ALAssetRepresentation.metadata 包含两个名为“PixelHeight”和“PixelWidth”的键。我的问题是:是否可以保证所有图像都存在这些
我有以下从 ALAssetRepresentation 中提取数据的代码。 ALAssetRepresentation *representation = ...; size_t size = [re
我是一名优秀的程序员,十分优秀!