2
我試圖用jcodec將圖像轉換爲視頻。獲得圖像的功能是:將字節數組或位圖轉換爲圖片
public void encodeNativeFrame(Picture pic) throws IOException
我可以給這個功能可按位圖或coverted到YUV420相同的位圖的字節數組。
我的問題是如何將位圖轉換爲圖片或將字節數組(字節[])轉換爲圖片。
我試圖用jcodec將圖像轉換爲視頻。獲得圖像的功能是:將字節數組或位圖轉換爲圖片
public void encodeNativeFrame(Picture pic) throws IOException
我可以給這個功能可按位圖或coverted到YUV420相同的位圖的字節數組。
我的問題是如何將位圖轉換爲圖片或將字節數組(字節[])轉換爲圖片。
首先,你需要創建一個位圖:
Bitmap bitmap = BitmapFactory.decodeByteArray(yourByteArray, 0, yourByteArray.length);
之後,得到一個畫布中,您將記錄=
Picture picture = new Picture();
Canvas canvas = picture.beginRecording(bitmap.getWidth(), bitmap.getHeight());
然後,畫出你的畫布
上的位圖canvas.drawBitmap(bitmap, null, new RectF(0f, 0f, (float) bitmap.getWidth, (float) bitmap.getHeight), null);
然後,結束記錄
picture.endRecording();
然後,圖片將包含您的位圖。
下面的方法這樣做:
public Picture fromByteArray(byte[] byteArray){
Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
Picture picture = new Picture();
Canvas canvas = picture.beginRecording(bitmap.getWidth(), bitmap.getHeight());
canvas.drawBitmap(bitmap, null, new RectF(0f, 0f, (float) bitmap.getWidth, (float) bitmap.getHeight), null);
picture.endRecording();
return picture;
}