2011-05-16 2 views
0

너비와 높이가 알려진 값으로 비어있는 비트 맵을 만들 필요가있다. 이 비트 맵의 ​​컨텍스트를 사용하여 MKOverlayVew에 이미지를 그리고 표시합니다. 누구든지 가장 쉬운 방법을 알고 있습니까?iPhone : 메모리에 비어있는 비트 맵을 만드는 방법?

+0

투명하게 비어 있습니까? 또는 일부 배경색 (검정, 흰색 등)으로 채워져있는 "비어 있음"? – hotpaw2

답변

1

다음 코드는이 트릭을 수행해야합니다. 원래부터 : CGBitmapContextCreate on the iPhone/iPad

 int width = 500; 
     int height = 500; 

     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
     unsigned char *rawData = malloc(height * width * 4); 
     memset(rawData, 0, height * width * 4); 

     NSUInteger bytesPerPixel = 4; 
     NSUInteger bytesPerRow = bytesPerPixel * width; 
     NSUInteger bitsPerComponent = 8; 
     CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); 
     // Do your thing and then release 
     CGColorSpaceRelease(colorSpace); 
     free(rawData); 
     CGContextRelease(context); 

가 그 질문에 게시 된 코드 차이, 그러나 영업 이익은 메모리 문제를 언급 있는지 확실하지 않습니다 그리고 내가 게시하도록하겠습니다이 코드에 어떤 없었어요.

+0

감사합니다. 이 코드는 실제로 작동합니다. 그리고 좋은 일. 결과적으로 응용 프로그램의 성능이 약 100 배 향상되었습니다. – martianex

+0

일단 CGBitmapContextCreate를 호출하면 inte rawData 메모리를 작성하여 픽셀을 수정할 수 있습니까? – webshaker

관련 문제