UIScrollView에 의해 제어되는 UIView에 표시되는 CGImage가 있습니다. 이미지는 일반적으로 알파 채널이없는 24 비트 색상의 1680 * 1050입니다.drawRect는 뷰가 축소 될 때 항상 전체 화면을 업데이트하려고합니다.
화상은 다음과 같이 생성된다 :
는 이미지 콘텐츠 m_pvBits의 픽셀을 변경하여 백그라운드에서 정기적으로 업데이트하여 UIView의 갱신된다CGImageRef bitmapClass::CreateBitmap(int width, int height, int imageSize, int colorDepth, int bytesPerRow)
{
unsigned char* m_pvBits = malloc(imageSize);
// Initializt bitmap buffer to black (red, green, blue)
memset(m_pvBits, 0, imageSize);
m_DataProviderRef =
CGDataProviderCreateWithData(NULL, m_pvBits, imageSize, NULL);
m_ColorSpaceRef =
CGColorSpaceCreateDeviceRGB();
return
CGImageCreate(width, height,
8, //kBitsPerComponent
colorDepth,
bytesPerRow,
m_ColorSpaceRef,
kCGBitmapByteOrderDefault | kCGImageAlphaNone,
m_DataProviderRef,
NULL, false, kCGRenderingIntentDefault);
}
:
[myView setNeedsDisplayInRect:rect];
는의 drawRect를 호출하는 다음과 같은 이미지를 표시합니다 :
- (void)drawRect:(CGRect)rect
{
CGRect imageRect;
imageRect.origin = CGPointMake(0.0, 0.0);
imageRect.size = CGSizeMake(self.imageWidth, self.imageHeight);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
// Drawing code
CGContextDrawImage(context, imageRect, (CGImageRef)pWindow->GetImageRef());
}
이것은 그는보기가 축소되지 않습니다 (축소). drawRect에서는 'rect'가 실제로는 직접 사용되지 않지만 'context'는 CGContextDrawImage가 업데이트해야하는 부분을 알고있는 것으로 보입니다.
내 문제는 setNeedsDisplayInRect를 사용하여 화면의 작은 영역 만 무효화해도 뷰가 축소되면 전체 화면에서 drawRect가 호출된다는 것입니다. 그래서 내 이미지가 1680 * 1050이고 작은 직사각형 (x, y, w, h) = (512, 640, 32, 32)을 무효화하면 drawRect는 (x, y, w, h) = , 0, 1680, 1050).
왜?