私はビットマップを使って指で何かを描きます。
まず、ビットマップに線を引きます。
次に、ビットマップを画面に描画します。
しかし、問題はこの方法を使用しているため、線がぼやけています。
以下は比較です。
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
}
それで、それの何が問題なのですか??
誰?