아이폰에 출력 할 xcode의 픽셀을 개별적으로 그리려고합니다. OpenGL이나 Quartz 코딩에 대해서는 잘 모르겠지만 Core Graphics에 대해서는 약간 알고 있습니다. 너비와 높이가 1 인 작은 직사각형을 그릴 생각 이었지만 이것을 코드로 구현하는 방법과이를 뷰에 표시하는 방법을 모릅니다. 어떤 도움이라도 대단히 감사합니다.드로잉 픽셀 - Objective-C/Cocoa
답변
모든 도면은 - (void)drawRect:(CGRect)rect
방법으로 이동해야합니다. [self setNeedsDisplay]
다시 그리기 코드에 플래그를 지정합니다. 문제는 다시 그리는 것입니다.
이전에 그려진 일부 픽셀에 누적 추가 된 픽셀을 그리려면 고유 한 비트 맵 메모리로 백업 된 고유 한 비트 맵 그래픽 콘텍스트를 만들어야합니다. 그런 다음 비트 맵 메모리에서 개별 픽셀을 설정하거나 그래픽 컨텍스트에 짧은 선이나 작은 사각형을 그릴 수 있습니다. 드로잉 컨텍스트를 표시하려면 먼저 CGImageRef로 변환하십시오. 그런 다음이 이미지를 뷰의 drawRect에서 서브 클래 싱 된 UIView로 그릴 수도 있고 이미지를 UIView의 CALayer 내용에 할당 할 수도 있습니다.
Apple 설명서의 CGBitmapContextCreate 및 CGBitmapContextCreateImage를 참조하십시오.
로 볼 수 있습니다 : 사용자 정의를 위해 http://www.musingpaw.com/2012/04/drawing-in-ios-apps.html
:
가 내 블로그에 당신이 iOS 앱에 픽셀을 그릴 때이 필요한 이유를 더 긴 설명, 플러스 일부 소스 코드 조각을 쓴 고정 된 크기와 색상의 점을 그릴 수있는 UIView 하위 클래스 :
// Make a UIView subclass
@interface PlotView : UIView
@property (nonatomic) CGContextRef context;
@property (nonatomic) CGLayerRef drawingLayer; // this is the drawing surface
- (void) plotPoint:(CGPoint) point; //public method for plotting
- (void) clear; // erases drawing surface
@end
// implementation
#define kDrawingColor ([UIColor yellowColor].CGColor)
#define kLineWeight (1.5)
@implementation PlotView
@synthesize context = _context, drawingLayer = _drawingLayer;
- (id) initPlotViewWithFrame:(CGRect) frame; {
self = [super initWithFrame:frame];
if (self) {
// this is total boilerplate, it rarely needs to change
self.backgroundColor = [UIColor clearColor];
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat width = frame.size.width;
CGFloat height = frame.size.height;
size_t bitsPerComponent = 8;
size_t bytesPerRow = (4 * width);
self.context = CGBitmapContextCreate(NULL, width, height, bitsPerComponent, bytesPerRow, colorspace, kCGImageAlphaPremultipliedFirst);
CGColorSpaceRelease(colorspace);
CGSize size = frame.size;
self.drawingLayer = CGLayerCreateWithContext(self.context, size, NULL);
}
return self;
}
// override drawRect to put drawing surface onto screen
// you don't actually call this directly, the system will call it
- (void) drawRect:(CGRect) rect; {
// this creates a new blank image, then gets the surface you've drawn on, and stamps it down
// at some point, the hardware will render this onto the screen
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGImageRef image = CGBitmapContextCreateImage(self.context);
CGRect bounds = [self bounds];
CGContextDrawImage(currentContext, bounds, image);
CGImageRelease(image);
CGContextDrawLayerInRect(currentContext, bounds, self.drawingLayer);
}
// simulate plotting dots by drawing a very short line with rounded ends
// if you need to draw some other kind of shape, study this part, along with the docs
- (void) plotPoint:(CGPoint) point; {
CGContextRef layerContext = CGLayerGetContext(self.drawingLayer); // get ready to draw on your drawing surface
// prepare to draw
CGContextSetLineWidth(layerContext, kLineWeight);
CGContextSetLineCap(layerContext, kCGLineCapRound);
CGContextSetStrokeColorWithColor(layerContext, kDrawingColor);
// draw onto surface by building a path, then stroking it
CGContextBeginPath(layerContext); // start
CGFloat x = point.x;
CGFloat y = point.y;
CGContextMoveToPoint(layerContext, x, y);
CGContextAddLineToPoint(layerContext, x, y);
CGContextStrokePath(layerContext); // finish
[self setNeedsDisplay]; // this tells system to call drawRect at a time of it's choosing
}
- (void) clear; {
CGContextClearRect(CGLayerGetContext(self.drawingLayer), [self bounds]);
[self setNeedsDisplay];
}
// teardown
- (void) dealloc; {
CGContextRelease(_context);
CGLayerRelease(_drawingLayer);
[super dealloc];
}
그냥 찾아서 사용해 봤습니다! 참고 : 내 UIView ("drawView") 영역에 내 응용 프로그램에서 그릴 수 얻으려면 나는 같은 viewDidLoad 메서드에서 하위 뷰로 PlotView 인스턴스를 추가 할했습니다. [self.drawView addSubview : self.plotView]; – SonarJetLens
- 1. 픽셀 드로잉 알고리즘
- 2. 빠른 픽셀 드로잉 라이브러리
- 3. 정확하게 픽셀 래스터에 맞지 않는 2D OpenGL 드로잉 라인
- 4. 드로잉 응용 프로그램에서 계속 드로잉
- 5. C# 드로잉 텍스트
- 6. 런타임 드로잉
- 7. 안드로이드 드로잉
- 8. 스레드 드로잉
- 9. Android 드로잉
- 10. 드로잉 문제
- 11. 드로잉 opencv?
- 12. 코어 그래픽 애니메이션 드로잉 (iPhone)
- 13. Canvas에서의 정확한 픽셀 이동
- 14. CSS의 픽셀 (픽셀)이란 무엇입니까?
- 15. WPF 픽셀 대 데스크톱 픽셀
- 16. 드로잉 응용 프로그램의 스크린 샷 만들기 + 2D 모양의 드로잉 개요
- 17. OpenGl 스타 드로잉
- 18. iPhone 드로잉 브라우저에서
- 19. BufferedImage를 통한 드로잉. repaint()
- 20. 코코아 : NSView 드로잉 rect
- 21. 사용자 정의 MKOverlay 드로잉
- 22. CGImageCreateWithJPEGDataProvider를 사용한 드로잉 성능?
- 23. cocos2d의 동적 드로잉?
- 24. 캔버스 html5 컨텍스트로 드로잉
- 25. 드로잉 NSImage 타일
- 26. JApplet 드로잉 모양
- 27. UIView 드로잉 문제
- 28. 안드로이드에서 Fingertip 드로잉 어플리케이션?
- 29. 비 드로잉 모질라 플러그인
- 30. 안드로이드 드로잉 - 배경 캐싱
CoreGraphics는 석영 – justin