I've got a UIView subclass (TraceView) which is 200 wide by 100 tall, and I'm attempting to draw on it pixel by pixel. In this case, I'm trying to draw a horizontal blue line that goes 75% of the way across. Instead, I get two vertical blue lines (one at the edge, one in the middle), that go 75% of the way up. It seems like the CGLayer I use has been rotated 90 degrees and shrunk 50%. What can I do to correct this?
At the top of the .m file:
#define WORLD_WIDTH 200
#define WORLD_HEIGHT 100
#define ABGR_BYTES 4
@implementation TraceView
int theImage[WORLD_WIDTH][WORLD_HEIGHT];
Overriding drawRect:
- (void)drawRect:(CGRect)rect {
CGContextRef theViewContext = UIGraphicsGetCurrentContext();
CGLayerRef theCGLayer = CGLayerCreateWithContext(theViewContext, rect.size, nil);
CGContextRef theCGLayerContext = CGLayerGetContext(theCGLayer);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext = CGBitmapContextCreate(theImage, WORLD_WIDTH, WORLD_HEIGHT, 8, WORLD_WIDTH * ABGR_BYTES, colorSpace, kCGImageAlphaPremultipliedLast);
// is ABGR
for(int i=0;i<150;i++) {
theImage[i][0]=0xFFFF0000;
}
CGImageRef image = CGBitmapContextCreateImage(bitmapContext);
CGContextDrawImage(theCGLayerContext, rect, image);
CGContextDrawLayerInRect(theViewContext, rect, theCGLayer);
}