我画了一些手指触摸使用位图。绘制位图到屏幕模糊?
首先我画线到位图。
然后将位图绘制到屏幕上。
但问题是使用这种方式,线条模糊。
下面是一个比较。
图片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