SORU
10 Ocak 2011, PAZARTESİ


Nasıl Android kamera yönünü düzgün ayarlayın.

Cihazın yönüne göre kamera yönünü ayarlamak için Android istiyorum ama hiçbir şey çalışıyor gibi görünüyor. Kameranın parametrelerini ama portre modunda kamera önizleme hep ters geliyor Yüzeyinde döndürmek için çalıştım. 90 doğru olduğu için derece saat yönünde döndürün. İşte şu anda kullanıyorum manzara modunda çalışan kod.

    SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() {

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        camera.stopPreview();
        camera.release();
        camera = null;
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {          
        initCamera();           
    }

    private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
        final double ASPECT_TOLERANCE = 0.2;
        double targetRatio = (double) w / h;
        if (sizes == null)
            return null;

        Size optimalSize = null;
        double minDiff = Double.MAX_VALUE;

        int targetHeight = h;

        // Try to find an size match aspect ratio and size
        for (Size size : sizes) {
            Log.d(TAG, "Checking size "   size.width   "w "   size.height
                      "h");
            double ratio = (double) size.width / size.height;
            if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
                continue;
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }

        // Cannot find the one match the aspect ratio, ignore the
        // requirement
        if (optimalSize == null) {
            minDiff = Double.MAX_VALUE;
            for (Size size : sizes) {
                if (Math.abs(size.height - targetHeight) < minDiff) {
                    optimalSize = size;
                    minDiff = Math.abs(size.height - targetHeight);
                }
            }
        }
        return optimalSize;
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        Camera.Parameters parameters = camera.getParameters();

        List<Size> sizes = parameters.getSupportedPreviewSizes();
        Size optimalSize = getOptimalPreviewSize(sizes, width, height);         
        Log.d(TAG, "Surface size is "   width   "w "   height   "h");
        Log.d(TAG, "Optimal size is "   optimalSize.width   "w "   optimalSize.height   "h");           
        parameters.setPreviewSize(optimalSize.width, optimalSize.height);           
        // parameters.setPreviewSize(width, height);            
        camera.setParameters(parameters);
        camera.startPreview();
    }
};  

CEVAP
28 ŞUBAT 2011, PAZARTESİ


Diğer üye ve benim sorunum:

Kamera Dönme sorunu farklı Cihazlar ve belirli bir Sürümüne bağlıdır.

Rotasyon Sorunu çözmek ve cihazların çoğu için iyidir . sürüm 1.6:

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        {   
            p.set("orientation", "portrait");
            p.set("rotation",90);
        }
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        {                               
            p.set("orientation", "landscape");          
            p.set("rotation", 90);
        }

Sürüm 2.1: örneğin cihaz üzerinde çalışması, cep X10, ama X8 ve Mini için iyidir . sorun Cannt düzeltme

Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
camera.setParameters(parameters);

Cihazlar için değil . sürüm 2.2:

camera.setDisplayOrientation(90);

http://code.google.com/p/android/issues/detail?id=1193#c42

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Hot For Nutrition

    Hot For Nutr

    26 ŞUBAT 2007
  • SPBedition

    SPBedition

    24 HAZİRAN 2013
  • TecNoob

    TecNoob

    15 AĞUSTOS 2013