canvas教程

学习使用Canvas绘图

字号+ 作者:H5之家 来源:H5之家 2017-05-05 17:03 我要评论( )

// 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 c

// 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);


 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • canvas 画六边形边框

    canvas 画六边形边框

    2017-05-05 12:00

  • Delphi的绘图功能[12]-TPen类下:学习橡皮线

    Delphi的绘图功能[12]-TPen类下:学习橡皮线

    2017-05-05 09:06

  • 妙味课堂HTML5视频教程——canvas基础5.zip

    妙味课堂HTML5视频教程——canvas基础5.zip

    2017-05-04 18:11

  • canvas系列教程1

    canvas系列教程1

    2017-05-04 14:00

网友点评
t