2012-09-09 2 views
1

카메라 미리보기에서 일부 이미지 처리를 시도하고 있지만 샘플 시간 이미지에서 너무 느려서 작은 크기로 처리합니다. 그런 다음 처리 된 (임계 값) 이미지를 미리보기 위에 오버레이합니다. 내 문제는 카메라 미리보기에 맞게 작은 이미지의 크기를 조정하면 픽셀이 같은 크기를 유지한다는 것입니다. 스케일링으로 인해 큰 픽셀을보고 싶습니다.하지만 그렇게 할 수 없습니다.Canvas scaling이 픽셀 크기를 유지합니다.

Scaled overlay pixels are of original size

:이 결과

class PathThread extends Thread implements PreviewCallback 
{ 
    private final int width, height; 
    private final SurfaceHolder holder; 
    private Canvas overlayCanvas; 
    private int samples = 8; 

    final private float scale; 
    final private Paint red, blue, yellow; 

    public PathThread(int canvasWidth, int canvasHeight, SurfaceView canvasView) 
    { 
     // This is how much smaller image I want 
     width = canvasWidth/samples; 
     height = canvasHeight/samples; 
     holder = canvasView.getHolder(); 

     // Scale to fit the camera preview SurfaceView 
     scale = (float) canvasView.getWidth()/height; 

     // No smoothing when scaling please 
     yellow = new Paint(); 
     yellow.setColor(Color.parseColor("#ffbb33")); 
     yellow.setAntiAlias(false); 
     yellow.setDither(false); 
     yellow.setFilterBitmap(false); 
    } 

    public void onPreviewFrame(byte[] data, Camera camera) 
    { 
     overlayCanvas = holder.lockCanvas(); 
     overlayCanvas.drawColor(0, Mode.CLEAR); 
     overlayCanvas.scale(scale, scale); 

     // Do the image processing and make a [samples] times smaller image 
     // Boring, pseudo-optimized, per-pixel thresholding process 

     holder.unlockCanvasAndPost(overlayCanvas); 
    } 
} 

다음 임계 값을 카메라 미리보기 이미지 바이트를 취득하지

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:keepScreenOn="true" 
    android:orientation="vertical" > 

    <SurfaceView 
     android:id="@+id/svPreview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <SurfaceView 
     android:id="@+id/svOverlay" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:adjustViewBounds="true" /> 
</RelativeLayout> 

그리고 스레드 : 여기

은 XML이다

조금 상쇄되었지만 그게 사실이라는 것을 알고 있습니다. 내 문제의 최소한.

답변

1

솔루션 :이 전화를했다 내가 그리는 서피스 뷰 SurfaceView의 소유자로

을 : 그것을 검색 2 일 이상 후

이해/아주 쉽게 찾을 매우 간단하지만 아니었다

canvasHolder.setFixedSize(width, height); 

나는 다른 값을 실험하고 내가 필요한 것을 발견했다. 이로 인해 큰 픽셀이됩니다.

관련 문제