如何在iphone中使用setpixel功能
答案 0 :(得分:0)
如果您正在绘制UIView,我不相信有任何方法可以设置单个像素。相反,请尝试通过覆盖UIView的drawRect:
方法来使用CoreGraphics:
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect pixelRect;
pixelRect.x = 100; // or whatever position needs a pixel drawn
pixelRect.y = 100;
pixelRect.width = 1;
pixelRect.height = 1;
CGContextSetRGBFillColor(ctx,1,1,1,1.0); // just fill with a white color
CGContextFillRect(ctx, pixelRect);
另一种方法可能是考虑使用OpenGL并只是这样绘制点:
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, rect.size.width, rect.size.height, 0, 0, 1); // set to the drawing rectangle's size
glDisable(GL_DEPTH_TEST);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.375, 0.375, 0);
glClear(GL_COLOR_BUFFER_BIT);
// draw the actual point
glBegin(GL_POINTS);
glColor3f(1.0f, 1.0f, 1.0f); // white color
glVertex2f(x, y);
glEnd();