iPhone开发应用中如何使BMP读取交显示解决方法

移动开发 iOS
iPhone开发应用中如何使BMP读取交显示解决方法是本文要介绍的内容,主要是来学习在iphone开发中,BMP显示的问题,本文介绍了两种解决方法。内容不多,主要是基于代码来实现内容。

iPhone开发应用中如何使BMP读取交显示解决方法是本文要介绍的内容,主要是来学习在iphone开发中,BMP显示的问题,本文介绍了两种解决方法。内容不多,主要是基于代码来实现内容。虽然在iphone下很少使用bmp格式的图片,但在此要介绍两种方法,让对bmp情有独钟的人,了确心中愿望。来 看本文具体详解。

  1. #define BMP_SIZE   320*480*3    
  2. #define BMP_HEADER_LENGTH 54    
  3.      
  4. //方法一:    
  5. CGImageRef GetImageData()    
  6. {    
  7.     unsigned char* pData=NULL;    
  8.     int i = 0;    
  9.      
  10.     int bitsPerComponent = 8;    
  11.     int bitsPerPixel = 24;    
  12.     int bytesPerRow = 3 * SCREEN_METRIC_WIDTH;    
  13.     NSInteger myLCDDataLength =     
  14. SCREEN_METRIC_WIDTH * SCREEN_METRIC_HEIGHT * 2;    
  15.     CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();    
  16.     CGBitmapInfo bmpInof = kCGBitmapByteOrderDefault;    
  17.     CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;    
  18.     CGDataProviderRef provider = nil;    
  19.     void*pBuffer = malloc(BMP_SIZE + BMP_HEADER_LENGTH);      
  20.     for(pData = pBufferi = 0; i < SCREEN_METRIC_WIDTH * SCREEN_METRIC_HEIGHT; ++i)    
  21.     {    
  22.         *pData++ = 0xFF; //R    
  23.         *pData++ = 0x0; //G    
  24.         *pData++ = 0x0; //B    
  25.     }    
  26.      
  27.     provider = CGDataProviderCreateWithData(NULL, pBuffer, myLCDDataLength, NULL);    
  28.      
  29.     return CGImageCreate(SCREEN_METRIC_WIDTH,SCREEN_METRIC_HEIGHT,    
  30.                          bitsPerComponent,    
  31.                          bitsPerPixel,    
  32.                          bytesPerRow,    
  33.                          colorSpaceRef,    
  34.                          bmpInof,    
  35.                          provider,    
  36.                          NULL,     
  37.                          NO,    
  38.                          renderingIntent);        
  39. }    
  40.      
  41. void GUI_DrawBMP()    
  42. {    
  43.     CGImageRef m_cgImage = GetImageData();    
  44.      
  45.     pUIImage = [ [ UIImage alloc] initWithCGImage:m_cgImage];    
  46.      
  47.     [pUIImage drawAtPoint:CGPointMake(0.0f,0.0f)];    
  48.      
  49.     [pUIImage dealloc];    
  50.      
  51. }    
  52.      
  53. //方法二:    
  54. const char* const g_pszFilePath = "/example.bmp";    
  55. FILE * pFile = fopen(g_pszFilePath, "rb");    
  56. if(NULL != pFile)    
  57. {    
  58.     void*pBuffer = malloc(BMP_SIZE + BMP_HEADER_LENGTH);       
  59.     if (NULL != pBuffer)    
  60.     {    
  61.     fseek(pFile , 0, SEEK_SET);    
  62.     fread(pBuffer, 1, 54, pFile);    
  63.     fclose(pFile);    
  64.     memset(pBuffer + BMP_HEADER_LENGTH, BMP_SIZE);    
  65.     NSData* pNSData = [ [NSData alloc] initWithBytes:pBuffer     
  66. length: BMP_SIZE + BMP_HEADER_LENGTH];    
  67.     UIImage* pUIImage = [ [ UIImage alloc] initWithData:myNSData];    
  68.     [pUIImage drawAtPoint:CGPointMake(0.0f,0.0f)];    
  69.     [pNSData dealloc];     
  70.     free(pBuffer);    
  71.     }    
  72. }   

小结:iPhone开发应用中如何使BMP读取交显示解决方法的内容介绍完了,希望通过本文的学习鞥对你有所帮助!

责任编辑:zhaolei 来源: 网络转载
相关推荐

2011-08-18 15:56:08

iPhone开发内存

2011-08-17 10:09:25

iPhone开发UIWebViewTouch事件

2011-07-07 15:45:45

iPhone SQLite 数据

2011-08-11 15:23:04

iPhoneNSBundleXcode

2011-08-08 14:07:49

iPhone开发 字体

2011-08-17 15:10:21

iPhone开发Web视图

2010-06-17 10:32:13

开机显示Grub

2011-08-19 10:35:19

iPhone应用Three20

2009-08-13 10:40:15

C#读取Excel

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-15 10:15:00

iPhone开发警告框

2010-09-28 13:53:59

sql text字段

2009-07-07 09:09:48

结构化综合布线光系统

2011-08-15 15:44:46

iPhone开发PDF

2011-08-18 16:24:44

iPhone开发图片

2011-08-09 17:12:30

iPhoneCFRunLoop

2011-08-12 14:33:06

iPhone缓存文件

2011-08-22 14:12:48

iPhone开发NSTableView

2011-08-15 11:37:20

iPhone开发Mask

2011-08-19 14:34:03

iPhone开发
点赞
收藏

51CTO技术栈公众号