繁体   English   中英

如何在iOS中将png / jpeg转换为.bmp

[英]How to convert png/jpeg to .bmp in iOS

如何将png / jpeg转换为.bmp图像? 我尝试了以下解决方案,但没有运气:

CGImageRef sourceRef = source.CGImage;
size_t width = CGImageGetWidth(sourceRef);
size_t height = CGImageGetHeight(sourceRef);

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

size_t bitsPerComponent = 8;
size_t bytesPerPixel    = 4;
size_t bytesPerRow      = (width * bitsPerComponent * bytesPerPixel + 7) / 8;
size_t dataSize         = bytesPerRow * height;

unsigned char *data = malloc(dataSize);
memset(data, 0, dataSize);


CGContextRef context = CGBitmapContextCreate(data, width, height,
                                             bitsPerComponent, bytesPerRow, colorSpace,
                                             kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

CGContextDrawImage(context, CGRectMake(0, 0, width, height), sourceRef);

CGColorSpaceRelease(colorSpace);
unsigned char *bitmapData = (unsigned char *)CGBitmapContextGetData(context);

在较高的层次上,您需要将.jpg放入NSBitmapImageRep对象中,然后让框架为您处理转换。

以下是MAC的链接: 如何使用Objective C将.jpg图像转换为.bmp格式?

有一个命令行工具可以帮助你从GITHUB

https://github.com/tonybeltramelli/TMXResolutionTool/

最好的方法是在UIImage中获取图像,然后将其转换为bitMap。

https://github.com/PaulSolt/UIImage-Conversion

这会对你有所帮助。

问候,

阿尼尔

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM