// To draw
private SurfaceHolder mSurfaceHolder = null;
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.i("FFMpegPlayer", "surfaceCreated");
this.mSurfaceHolder = holder;
this.mDrawThread = new DrawThread(this);
}
Canvas canvas = mSurfaceHolder.lockCanvas();
if (canvas == null) {
return;
}
canvas.drawRGB(0, 0, 0);
Bitmap bmp;
String sizeString = "";
try {
bmp = RenderFrame();//获取图像BMP数据
if (bmp != null) {
canvas.save();
int width = this.mWidth;
int height = this.mHeight;
float bmpWidth = (float)(bmp.getWidth());
float bmpHeight = (float)(bmp.getHeight());
float ratiow = width / bmpWidth;
float ratioh = height / bmpHeight ;
float ratio = ratiow > ratioh ? ratiow : ratioh;
float moveX = ((bmpWidth * ratio - width) / 2.0f);
float moveY = ((bmpHeight * ratio - height) / 2.0f);
canvas.translate(-moveX, -moveY);
canvas.scale(ratio, ratio);
canvas.drawBitmap(bmp, 0, 0, null);
canvas.restore();
}
} catch (Exception e) {
}
this.mSurfaceHolder.unlockCanvasAndPost(canvas);