簡體   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