Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone CGLayer出现在错误的方向_Iphone_Uiview_Quartz Graphics - Fatal编程技术网

Iphone CGLayer出现在错误的方向

Iphone CGLayer出现在错误的方向,iphone,uiview,quartz-graphics,Iphone,Uiview,Quartz Graphics,我有一个UIView子类(TraceView),它是200宽x 100高,我正在尝试逐像素地绘制它。在这个例子中,我试图画一条水平的蓝线,它穿过75%的道路。相反,我得到了两条垂直的蓝线(一条在边缘,一条在中间),它们向上延伸了75%。看起来我使用的CGLayer已经旋转了90度,缩小了50%。我能做些什么来纠正这个问题 在.m文件的顶部: #define WORLD_WIDTH 200 #define WORLD_HEIGHT 100 #define ABGR_BYTES 4 @implem

我有一个UIView子类(TraceView),它是200宽x 100高,我正在尝试逐像素地绘制它。在这个例子中,我试图画一条水平的蓝线,它穿过75%的道路。相反,我得到了两条垂直的蓝线(一条在边缘,一条在中间),它们向上延伸了75%。看起来我使用的CGLayer已经旋转了90度,缩小了50%。我能做些什么来纠正这个问题

在.m文件的顶部:

#define WORLD_WIDTH 200
#define WORLD_HEIGHT 100
#define ABGR_BYTES 4

@implementation TraceView

int theImage[WORLD_WIDTH][WORLD_HEIGHT];
覆盖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);

}
-(void)drawRect:(CGRect)rect{
CGContextRef theViewContext=UIGraphicsGetCurrentContext();
cglayerreftheclayer=CGLayerCreateWithContext(theViewContext,rect.size,nil);
CGContextRef theCGLayerContext=CGLayerGetContext(theCGLayer);
CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext=CGBitmapContextCreate(图像、世界宽度、世界高度、8、世界宽度*ABGR字节、颜色空间、KCGIMAGEAlphaPremultipledLast);
//是ABGR吗

对于(int i=0;i好的,我让它工作了,傻我

如果我将数组视为图像[y][x]而不是图像[x][y],那么它可以正常工作