我畫了一些手指觸摸使用位圖。繪製位圖到屏幕模糊?
首先我畫線到位圖。
然後將位圖繪製到屏幕上。
但問題是使用這種方式,線條模糊。
下面是一個比較。
圖片1被直接繪製到屏幕上。 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
}
那麼它有什麼問題?
有人嗎?
對於視網膜設備上下文,您應該使用雙倍高度和寬度。 – yinkou