2012-04-04 3 views
2

터치되는 모든 픽셀을 감지 할 수 있습니까? 더 구체적으로, 사용자가 화면을 터치하면, 사용자가 접촉 한 지점의 클러스터의 모든 x-y 좌표를 추적 할 수 있습니까? 사용자가 엄지 손가락으로 그릴 때와 손가락 끝으로 그릴 때의 차이를 어떻게 알 수 있습니까? 사용자가 화면을 터치하는 방식에 따라 브러시의 차이를 반영하고 터치 한 모든 픽셀을 추적하려고합니다.터치 포인트에서 개별 픽셀 얻기

나는 현재 애플 개발자 사이트에서 GLPaint 샘플에서 다음 코드를 사용하고 있습니다 :

http://developer.apple.com/library/ios/#samplecode/GLPaint/Introduction/Intro.html

샘플 코드는 허용 미리 정의 된 브러시 크기와 그리기 길을 따라의 x, y 좌표를 추적. 사용자가 화면을 터치하고 시간 경과에 따라 터치되는 모든 픽셀을 추적하는 방식에 따라 브러시를 어떻게 변경할 수 있습니까?

// Drawings a line onscreen based on where the user touches 

- (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end 

{ 
    NSLog(@"x:%f y:%f",start.x, start.y); 

    static GLfloat*   vertexBuffer = NULL; 

    static NSUInteger  vertexMax = 64; 

    NSUInteger    vertexCount = 0, 

        count, 

        i; 



    [EAGLContext setCurrentContext:context]; 

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); 



    // Convert locations from Points to Pixels 

    CGFloat scale = self.contentScaleFactor; 

    start.x *= scale; 

    start.y *= scale; 

    end.x *= scale; 

    end.y *= scale; 



    // Allocate vertex array buffer 

    if(vertexBuffer == NULL) 

      vertexBuffer = malloc(vertexMax * 2 * sizeof(GLfloat)); 



    // Add points to the buffer so there are drawing points every X pixels 

    count = MAX(ceilf(sqrtf((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y))/kBrushPixelStep), 1); 

    for(i = 0; i < count; ++i) { 

      if(vertexCount == vertexMax) { 

       vertexMax = 2 * vertexMax; 

       vertexBuffer = realloc(vertexBuffer, vertexMax * 2 * sizeof(GLfloat)); 

      } 



      vertexBuffer[2 * vertexCount + 0] = start.x + (end.x - start.x) * ((GLfloat)i/(GLfloat)count); 

      vertexBuffer[2 * vertexCount + 1] = start.y + (end.y - start.y) * ((GLfloat)i/(GLfloat)count); 

      vertexCount += 1; 

    } 



    // Render the vertex array 

    glVertexPointer(2, GL_FLOAT, 0, vertexBuffer); 

    glDrawArrays(GL_POINTS, 0, vertexCount); 



    // Display the buffer 

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); 

    [context presentRenderbuffer:GL_RENDERBUFFER_OES]; 

} 


// Handles the start of a touch 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 

{ 

    CGRect     bounds = [self bounds]; 

    UITouch*  touch = [[event touchesForView:self] anyObject]; 

    firstTouch = YES; 

    // Convert touch point from UIView referential to OpenGL one (upside-down flip) 

    location = [touch locationInView:self]; 

    location.y = bounds.size.height - location.y; 

} 

// Handles the continuation of a touch. 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 

{ 

    CGRect     bounds = [self bounds]; 

    UITouch*    touch = [[event touchesForView:self] anyObject]; 



    // Convert touch point from UIView referential to OpenGL one (upside-down flip) 

    if (firstTouch) { 

      firstTouch = NO; 

      previousLocation = [touch previousLocationInView:self]; 

      previousLocation.y = bounds.size.height - previousLocation.y; 

    } else { 

      location = [touch locationInView:self]; 

     location.y = bounds.size.height - location.y; 

      previousLocation = [touch previousLocationInView:self]; 

      previousLocation.y = bounds.size.height - previousLocation.y; 

    } 



    // Render the stroke 

    [self renderLineFromPoint:previousLocation toPoint:location]; 

} 



// Handles the end of a touch event when the touch is a tap. 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 

{ 

    CGRect     bounds = [self bounds]; 

    UITouch*  touch = [[event touchesForView:self] anyObject]; 

    if (firstTouch) { 

      firstTouch = NO; 

      previousLocation = [touch previousLocationInView:self]; 

      previousLocation.y = bounds.size.height - previousLocation.y; 

      [self renderLineFromPoint:previousLocation toPoint:location]; 

    } 

} 


// Handles the end of a touch event. 

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 

{ 

    // If appropriate, add code necessary to save the state of the application. 

    // This application is not saving state. 

} 

답변

1

AFAIK 터치 할 때 터치 영역에 액세스하는 API가 없습니다. 나는 용량 성 터치 스크린의 한계를 감안할 때, 당신이 원하는 것이 물리적으로 가능한지 여부는 모르겠다. 최근 코코아 헤드에서 프리젠 테이션을 떠 올렸지 만 일부 정보는 트랙 패드 용 OS X (개인용 API를 통해)에서 사용할 수 있었지만 iOS에서는 사용할 수 없다는 것이 입증되었습니다.

나는이 그래픽 태블릿 자신의 센서 기술이 내장되어 특별한 스타일러스를 사용 이유 중 하나입니다 생각합니다.

부분적인 해결 방법, 드로잉 응용 프로그램에 대한 일부 데스크톱 응용 프로그램처럼 "잉크"를 시뮬레이션 할 수 있습니다 : 사용자의 터치가 특정 지점에 남아 있으면 잉크가 "펜"에서 나오고 점차적으로 "용지"로 확산되는 것처럼 그립니다.

+0

답변 해 주셔서 감사합니다. 이것이 Android에서 가능한지 알고 있습니까? – HappyAppDeveloper

+0

나도 몰라, 미안해, 안드로이드 개발하지 않아. 그래도 다른 사람들이 답을 얻을 것이라고 확신합니다. 검색에서 아무 것도 찾을 수없는 경우 Android로 태그 된 새로운 질문을 게시하는 것이 좋습니다. –

1

iPad의 Broadcomm 하드웨어가 64 Hz로 화면을 스캔합니다. 이것은 터치 스크린 전극을 구성하는 39 개의 투명한 도전 층에 각각 400 μs의 신호를 연속적으로가함으로써 수행됩니다. 손가락이 0.015625 초 내에 픽셀 거리보다 많이 이동하면 터치 이벤트가 더 많이 발생하도록 화면의 다른 부분을 측정 중이므로 하드웨어에서이를 감지 할 수 없습니다.

iOS 또는 Android와 상관없이 동일합니다. 저가의 Android 태블릿과 대형 화면은 스캔 속도가 느리기 때문에 터치 이벤트가 훨씬 더 넓어집니다.

와콤 타블렛은 디지타이저를 100Hz로 실행하므로 포인트 시퀀스가 ​​더 미세하지만 스타일러스가 두 측정 사이에 닿는 픽셀은 놓치게됩니다.

관련 문제