UIView
int の配列をinにブリットする方法の例をたくさん見つけましdrawRect
たが、最も単純なものはまだ私を困惑させています。これは問題なく動作しますが、まだ 3 つの質問があります。
~ なぜ 2 つのコンテキストがあるのですか?
〜なぜpush
/pop
文脈?
〜コピーを回避できますか?(アップルのドキュメントによると、CGBitmapContextCreateImage はメモリ ブロックをコピーします)
- (void)drawRect:(CGRect)rect {
CGColorSpaceRef color = CGColorSpaceCreateDeviceRGB();
int PIX[9] = { 0xff00ffff,0xff0000ff,0xff00ff00,
0xff0000ff,0xff00ffff,0xff0000ff,
0xff00ff00,0xff0000ff,0xff00ffff};
CGContextRef context = CGBitmapContextCreate((void*)PIX,3,3,8,4*3,color,kCGImageAlphaPremultipliedLast);
UIGraphicsPushContext(context);
CGImageRef image = CGBitmapContextCreateImage(context);
UIGraphicsPopContext();
CGContextRelease(context);
CGColorSpaceRelease(color);
CGContextRef c=UIGraphicsGetCurrentContext();
CGContextDrawImage(c, CGRectMake(0, 0, 10, 10), image);
CGImageRelease(image);
}