2017-07-19 9 views
0

ImageFormat NV21のカメラを使用して、NV21データを取得すると、このメソッドを使用してImageViewに表示できるバイトを取得しようとしています。ビットマップ圧縮が100になった理由

FONTのFACE:

public static byte[] n21ToBitmap(byte[] data, Camera camera) { 
    try { 
    Camera.Parameters parameters = camera.getParameters(); 
    Camera.Size size = parameters.getPreviewSize(); 
    YuvImage image = 
     new YuvImage(data, parameters.getPreviewFormat(), size.width, size.height, null); 
    ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
    image.compressToJpeg(new Rect(0, 0, size.width, size.height), 100, stream); 
    Bitmap originBitmap = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size()); 
    stream.close(); 
    Matrix matrix = new Matrix(); 
    matrix.postRotate(270); 
    Bitmap rotateBitmap = 
     Bitmap.createBitmap(originBitmap, 0, 0, originBitmap.getWidth(), originBitmap.getHeight(), 
      matrix, true); 
    Bitmap temp = rotateBitmap.copy(rotateBitmap.getConfig(), true); 
    Log.e("TAG", "n21ToBitmap(ImageUtils.java:" 
     + Thread.currentThread().getStackTrace()[2].getLineNumber() 
     + ")" 
     + "temp:" 
     + temp.getByteCount()); 
    stream = new ByteArrayOutputStream(); 
    temp.compress(Bitmap.CompressFormat.JPEG, 100, stream); 
    byte[] bytes = stream.toByteArray(); 
    Log.e("TAG", "n21ToBitmap(ImageUtils.java:" 
     + Thread.currentThread().getStackTrace()[2].getLineNumber() 
     + ")" 
     + "bytes:" 
     + bytes.length); 
    return bytes; 
} catch (Exception ex) { 
    Log.e(TAG, "Error:" + ex.getMessage()); 
} 
    return null; 
} 

そしてLOG:だから

n21ToBitmap(ImageUtils.java:103)temp: 2073600 
n21ToBitmap(ImageUtils.java:112)bytes:311627 

、なぜバイト長がsmallarになりますか?

+1

これはJPG形式のコンプレッサーです。 – Vyacheslav

+0

しかし、システムカメラを使って写真を撮ると、大きな画像が得られますか?それもJPG画像です。 – ChengTao

答えて

0

バイトの長さは配列のサイズですので、各配列のインデックスにもう一度バイトで値があります。

バイト[]バイト; bytest.length =配列サイズ。

あなたの配列のサイズ= 20 = bytest.length; と各インデックスにはいくつかのバイト値があります。 各インデックスに含まれる1024バイトを仮定します。

したがって合計サイズ= 20×1024、これはあなたのケース配列長の実寸

ある311627であり、各インデックスはそれぞれの値 ので合計サイズ= 311627 *値のいくつかのバイトを有しますindex

関連する問題