[英]How to convert .cpbitmap to readable image (png, jpg, jpeg…)
I like to convert an .cpbitmap file to an image format that can be displayed in UIImageView. 我喜欢将.cpbitmap文件转换为可以在UIImageView中显示的图像格式。 Is there a way to do this in Objective-C? 在Objective-C中有没有办法做到这一点? The app will run on jailbroken Devices, so thats not a big deal. 该应用程序将在越狱设备上运行,因此没什么大不了的。
Import private AppSupport.framework
and declare this 导入私有AppSupport.framework
并声明此
CFArrayRef CPBitmapCreateImagesFromData(CFDataRef cpbitmap, void*, int, void*);
This function will return an array of CGImageRef
objects. 此函数将返回CGImageRef
对象的数组。 First argument is data from .cpbitmap
file. 第一个参数是.cpbitmap
文件中的数据。 Other arguments are unknown to me (one of them is probably CFAllocatorRef
) so I checked how iOS calls this function and used the same values. 其他参数对我来说是未知的(其中一个可能是CFAllocatorRef
),因此我检查了iOS如何调用此函数并使用了相同的值。 Here is how I did it 这是我做的
CPBitmapCreateImagesFromData([NSData dataWithContentsOfFile:@"LockBackground.cpbitmap"], NULL, 1, NULL);
I also wanted to convert HomeBackground.cpbitmap / LockBackground.cpbitmap from Library/Springboard. 我还想从Library / Springboard转换HomeBackground.cpbitmap / LockBackground.cpbitmap。
The following worked for me: @creker: Thank you! 以下为我工作:@creker:谢谢!
CFArrayRef CPBitmapCreateImagesFromData(CFDataRef cpbitmap, void*, int, void*);
CFArrayRef someArrayRef = CPBitmapCreateImagesFromData((__bridge CFDataRef)([NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"LockBackground" ofType:@"cpbitmap"]]), NULL, 1, NULL);
NSArray *array = (__bridge NSArray*)someArrayRef;
UIImage *test = [UIImage imageWithCGImage:(__bridge CGImageRef)(array[0])];
I added a breakpoint after the last line and extracted the image with XCode -> test -> Preview. 我在最后一行之后添加了一个断点,并使用XCode-> test-> Preview提取了图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.