2013-06-19 1 views
0

손가락 터치 사용 비트 맵을 그립니다.화면에 비트 맵 그리기가 흐리게 ???

먼저 비트 맵에 선을 그립니다.

그런 다음 비트 맵을 화면에 그립니다.

하지만이 방법을 사용하면 선이 흐려집니다.

아래는 비교입니다.

enter image description here

enter image description here

PICTURE1 직접 스크린 상에 드로잉된다. picture2가 비트 맵을 사용 중입니다. 내 코드는 다음과 같습니다.

- (BOOL)CreateBitmapContext:(int)pixelsWide High:(int)pixelsHight 
{ 
CGColorSpaceRef colorSpace; 
void *   bitmapData; 
int   bitmapByteCount; 
int   bitMapBytesPerRow; 

bitMapBytesPerRow = (pixelsWide * 4); 
bitmapByteCount = (bitMapBytesPerRow * pixelsHight); 

colorSpace = CGColorSpaceCreateDeviceRGB(); 
bitmapData = malloc(bitmapByteCount); 
if (bitmapData == NULL) 
{ 
    CGColorSpaceRelease(colorSpace); 
    return NO; 
} 
tempContext = CGBitmapContextCreate(bitmapData, pixelsWide, pixelsHight, 8, bitMapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); 



if (tempContext == NULL) 
{ 
    CGColorSpaceRelease(colorSpace); 
    free(bitmapData); 
    return NO; 
} 
CGColorSpaceRelease(colorSpace); 
return YES; 
} 


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
UITouch *touch = [touches anyObject]; 
CGPoint p = [touch locationInView:self]; 
[tool setFirstPoint:p]; 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
UITouch *touch = [touches anyObject]; 
CGPoint p = [touch locationInView:self]; 
CGPoint previous = [touch previousLocationInView:self]; 
[tool moveFromPoint:previous toPoint:p]; 
[tool draw:tempContext]; 
[self setNeedsDisplay]; 
} 


- (void)drawRect:(CGRect)rect 
{ 
// Drawing code 
CGContextRef myContext = UIGraphicsGetCurrentContext(); 

myImage = CGBitmapContextCreateImage (tempContext);// 5 
CGContextDrawImage(myContext, rect, myImage);// 6 
} 

그래서 무엇이 잘못 되었습니까 ??

누구나?

+1

망막 장치의 컨텍스트에 두 배의 너비와 너비를 사용해야합니다. – yinkou

답변

1

기기에 망막 화면이있는 것 같습니다. 이 화면에서 화면의 픽셀 해상도와 동일한 비트 맵을 할당해야합니다. 그렇지 않으면 다시 렌더링 할 때 약간 흐려집니다. 혼란스러운 부분은 픽셀 해상도를 결정하기 위해 [[UIScreen mainScreen] bounds]을 수행하면 이미지가 필요한 픽셀 해상도의 절반이됩니다. 경계 값은 픽셀이 아닌 밀도 독립적 인 점을 나타 내기 때문입니다. 망막 장치에 2.0을 반환하는 [[UIScreen mainscreen] scale]을 읽음으로써이를 보상 할 수 있습니다.

+0

그래, 너는'- (BOOL) CreateBitmapContext : (int) pixelsWide High : (int) pixelsHight'에'[[UIScreen mainScreen] scale]'로 넘겨야한다. – Idles

+0

하지만 다음과 같은 코드를 타이핑 할 때 : 'float scaleFactor = [[UIScreen mainScreen] scale]; myBitmapContext = CGBitmapContextCreate (bitmapData, size.width, size.height, 8, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); if (Retina) { CGContextScaleCTM (myBitmapContext, scaleFactor, scaleFactor); }' 여전히 올바르지 않습니다. – Domlin

+0

컨텍스트 눈금을 설정하지 마십시오. 만들고있는 컨텍스트의 크기를 변경하십시오. 일명 CGBitmapContextCreate의 scaleFactor에 무조건 곱할 수 있습니다 (망막이 아닌 화면에서는 눈금이 1.0이므로 if-check가 필요하지 않습니다). – Idles

관련 문제