3
정말 큰 이미지를 표시하는 CATiledLayer 지원 UIScrollView가 있습니다. 내가 얻고 싶은 것은이 뷰를 UIImage로 캡쳐하는 것입니다 (진행 막대보기의 배경으로 사용). 몇 가지 문제가 있습니다iOS - CATiledLayer renderInContext : 결과가 왜곡됩니다.
"100 %"줌이 내가있는 ScrollView 확대하면 될 타일 중 일부는 왜곡 (규모 및/또는 오프셋- 거의 내가 코드를 작성하지 않은
- 때로는 픽셀 화되는 캡처 한 이미지를 제외하고, 작동 애플의 PhotoScroller 샘플, 그것을 repro 수하려고) 나쁜, 그래서 그것을
이에 대한 다른 유래 항목을 검사하지만, 그들은 ... 이미지 캡처의
코드 도움 많이되지 않은 :
CGRect rect = [view bounds];
UIImage* img = nil;
if ([view isKindOfClass:[UIScrollView class]])
{
UIScrollView* scrollview = (UIScrollView*)view;
CGPoint contentOffset = scrollview.contentOffset;
UIGraphicsBeginImageContextWithOptions(rect.size, view.opaque, 0.0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, -contentOffset.x, -contentOffset.y);
[view.layer renderInContext:ctx];
img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
그리고 타일 뷰의의 drawRect의 코드 : 방법 :
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
if (self.clipContent)
{
CGContextSaveGState(context);
CGFloat color[4] = {1.0, 1.0f, 1.0f, 1.0f};
CGContextSetFillColor(context, color);
CGContextFillRect(context, self.bounds);
CGRect clips[] = {
CGRectMake(self.bounds.size.width/2.0, 0,
self.bounds.size.height/2.0 , self.bounds.size.width/2.0)
};
CGContextClipToRects(context, clips, sizeof(clips)/sizeof(clips[0]));
}
CGFloat scale = CGContextGetCTM(context).a;
CGSize tileSize = [_dataSource tileSize];
double width = (double)tileSize.width/(double)scale;//pow(2.0, (int)log2(scale));
double height = (double)tileSize.height/(double)scale;//pow(2.0, (int)log2(scale));
int firstCol = floorf(CGRectGetMinX(rect)/width);
int lastCol = floorf((CGRectGetMaxX(rect) - 1)/width);
int firstRow = floorf(CGRectGetMinY(rect)/height);
int lastRow = floorf((CGRectGetMaxY(rect) - 1)/height);
for (int row = firstRow; row <= lastRow; row++) {
for (int col = firstCol; col <= lastCol; col++) {
UIImage* tileImage = [_dataSource tileForScale:scale row:row col:col];
CGRect tileRect = CGRectMake(width * col, height * row, width, height);
tileRect = CGRectIntersection(rect, tileRect);
[tileImage drawInRect:tileRect];
}
}
if (self.clipContent)
CGContextRestoreGState(context);
}
아이디어가 있으십니까?
감사합니다. 이 게시물을 찾기 전에 몇 시간 동안 잘못 렌더링 된 스냅 샷으로 고생했습니다. –
하지만 이렇게하면 이미지가 왜곡됩니다! 그 모양에 전혀 없습니다. @보호 시설 –