1

丸 3 日間検索し、多くの関連情報が見つかりましたが、コンピュータ グラフィックスの知識が不足しているため、十分に正確なものはありませんでした。ここで質問することに決めました。

明確にするために、

1)私はFrameLayoutを持っています

2) TextureView を追加しました

3) LayoutParams を FrameLayout に一種の正方形の形状に設定したため、どういうわけか TextureView もそれに応じてサイズ変更され、正方形になり、あまり混乱しません。

4) カメラ プレビュー作業と TextureView 表示作業の間のすべてが正常に動作しますが、

4!) SurfaceView の時代と同じように。カメラ プレビュー データを、カメラ プレビュー サイズに合わないビューに強制的に描画すると、最終結果が引き伸ばされてしまいます。

4.) FrameLayout/TextureView のサイズをプログラムで 4:3/~16:9 (Landscap または Portrait) にする方法を知っているということですが、実際には正方形にする必要があり、もちろん引き伸ばされないようにする必要があります。

5?) openGL Thin を介して SurfaceTexture データを前処理する必要があると思います。(これは非常に明白だと思いますが、よくわかりません。結果を達成するためのまったく異なる方法があれば、それも高く評価されます。

5) 事前質問の仕事について。これを行うサンプルはたくさんありますが、プレーンな SurfaceView または GLSurfaceView でのみです。私は元のopenGLプログラミングにあまり慣れていないので。コードを自分のプロジェクトにモーフィングしようとすると苦労しました

5+) いいえ、TextureView を使用する必要があります。Google が Camera サンプルを TextureView を使用するように転送したため、その理由が疑わしい場合は、TextureView + openGL コンボの扱いを学ぶ必要があると思います。とにかく、TextureView がステージに登場するのは、単純に View のように動作し、View のみを使用し、軽量な openGL 処理と連携してスクラッチを発生させないようにするためです。

6) 私は本当にそれらのオンライン サンプルを私のものに移植することができません。SurfaceTexture (omg) で openGL コンテキストをアタッチするのにも問題があります

7) はい、スケルトンのようなコード構造があり、drawFrame impl 以外はすべて機能します。一体何を入れたらいいんだ

アクティビティ

public class MainActivity extends ActionBarActivity {

private ImageView imageView;
private TextView textView;

private Camera mCamera;
private MirrorScope mScope;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageView = (ImageView) findViewById(R.id.qrCode);
    textView = (TextView) findViewById(R.id.title);

    // Create an instance of Camera
    mCamera = getCameraInstance();

    // Create our Preview view and set it as the content of our activity.
    mScope = new MirrorScope(this, mCamera);
    mScope.setSurfaceTextureListener(mScope);
    FrameLayout scopeDrawer = (FrameLayout) findViewById(R.id.camera_preview);
    scopeDrawer.setLayoutParams(new LinearLayout.LayoutParams(700,700));

    scopeDrawer.addView(mScope);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}


/** Check if this device has a camera */
private boolean checkCameraHardware(Context context) {
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
        // this device has a camera
        return true;
    } else {
        // no camera on this device
        return false;
    }
}

/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(){
    Camera c = null;
    try {
        c = Camera.open(); // attempt to get a Camera instance
    }
    catch (Exception e){
        // Camera is not available (in use or does not exist)
    }
    return c; // returns null if camera is unavailable
}

}

テクスチャビュー

    public class MirrorScope extends TextureView  implements TextureView.SurfaceTextureListener {

    private Camera mCamera;  
    private Context mContext;
    private TextureView mTextureView;  
    private ScopeGLThread renderer;

    public MirrorScope(Context context , Camera camera) {  
        super(context);  
        mCamera = camera;  
        // TODO Auto-generated constructor stub  
    }  
    @Override  
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width,  
            int height) {  
//        mCamera = Camera.open();  
        try {  
            mCamera.setPreviewTexture(surface);  
            mCamera.startPreview();  
        } catch (IOException ioe) {  
            // Something bad happened  
        }  
        renderer = new ScopeGLThread(surface);
        renderer.start();
    }  

    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width,  
            int height) {  
        // Ignored, Camera does all the work for us  
    }  

    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {  
        renderer = null;  
        mCamera.stopPreview();  
        mCamera.release();  
        return true;  
    }  

    public void onSurfaceTextureUpdated(SurfaceTexture surface) {  
        // Invoked every time there's a new Camera preview frame 
        //renderer.notify();

    }  

}  

openGL スレッド

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.egl.EGLSurface;

import android.graphics.SurfaceTexture;
import android.opengl.EGL14;
import android.util.Log;

public class ScopeGLThread extends Thread {

    SurfaceTexture mSurface;
    EGL10 mEgl;
    EGLDisplay mEglDisplay;
    EGLConfig mEglConfig;
    EGLContext mEglContext;
    EGLSurface mEglSurface;

    public ScopeGLThread(SurfaceTexture surface) {
        mSurface = surface;
    }

    @Override
    public void run() {
        initGL();

        while(true) {
            drawFrame();
            Log.v("omg","oooomg"); //this do print thus I think the main loop is kidda work-ful
            //wait(); //however this hurts even with try/catch bloack it kills my app
        }
    }

    private void initGL() {
        mEgl = (EGL10)EGLContext.getEGL();
        mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

        int versions[] = new int[2];
        mEgl.eglInitialize(mEglDisplay, versions);

        int configsCount[] = new int[1];
        EGLConfig configs[] = new EGLConfig[1];
        int configSpec[] = new int[]{
            EGL10.EGL_RENDERABLE_TYPE, 
            EGL14.EGL_OPENGL_ES2_BIT,
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_ALPHA_SIZE, 8,
            EGL10.EGL_DEPTH_SIZE, 0,
            EGL10.EGL_STENCIL_SIZE, 0,
            EGL10.EGL_NONE };
        mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, configsCount);
        mEglConfig = configs[0];

        int contextSpec[] = new int[]{
                EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
                EGL10.EGL_NONE };
        mEglContext = mEgl.eglCreateContext(mEglDisplay, mEglConfig, EGL10.EGL_NO_CONTEXT, contextSpec);

        mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, mSurface, null);

        mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext);
    }

    private void drawFrame() {
        //mSurface.attachToGLContext(1);
        //mSurface.detachFromGLContext();
        //mEgl..glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        //mSurface.updateTexImage();
    // everything I put here kills everything ( and some deleted other kind of trying)
    }


}

gl インスタンスを取得するにはどうすればよいですか? 一部のサンプルが gl を使用している場合 (どこからともなく... または引数)、他のサンプルが EGL14.blahblah のものを使用している場合、混乱していることがわかります。つまり...ああ、私はopenGLを本当に知らないし、Android.comのkhronosパッケージリファレンスは無効です...)

正確な問題を段階的に解決するチュートリアルが本当に必要ですが、それをテキスト形式で明確に説明すれば、それも素晴らしいでしょう. 正方形が必要な場合は、カメラ プレビュー データの左上の正方形をトリミングするだけで簡単に作成できると思います。それはとても役に立ちます。はい、ある種のフィルター関数を追加する必要があるかもしれないので、二乗問題をハックしないでください。私はこれをopenGL経由で行うと主張しています。

ところで、私の国のネットワーク状況により、Google のサンプルにアクセスできません。私は満足のいく事前質問検索の仕事をすることはできませんが、そのことをお詫びします。

4

2 に答える 2

0

GitHub で私の小さなサンプルを参照してください。私はまったく拡張 しないことを選択しandroid.view.TextureViewました。あなたの走行距離は異なる場合があります。

答えは、TextureView.SurfaceTextureListener.onSurfaceTextureAvailable()オーバーライドするコールバックにあります。変換 を見てくださいMatrix。アスペクト比の違いを補正したいtransform.setScale()場合は、満足のいく結果が得られるまで試行錯誤するだけです。公式ドキュメントによると、

一部の変換では、コンテンツがこのビューの境界内に含まれるすべてのピクセルを描画できない場合があります。このような状況では、このテクスチャ ビューが不透明にマークされていないことを確認してください。

私は彼らが何について話しているのか完全に理解していないことを告白しなければなりませんが、実験はMatrix、必要に応じてカメラプレビューの効果的なトリミングを実現できる権利を選択することを示しています.

于 2014-09-17T09:02:56.640 に答える