canvas教程

android画图学习笔记

字号+ 作者:H5之家 来源:H5之家 2015-10-05 15:08 我要评论( )

tile2.draw(canvas); Drawable tile3 = r.getDrawable(R.drawable.greenstar); tile3.setBounds(mTileSize*2, 0, mTileSize*3, mTileSize); tile3.draw(canvas); canvas.drawBitmap(bitmap, 0, 0, mPaint); Resources r = this.getContext().getResources();

tile2.draw(canvas);

Drawable tile3 = r.getDrawable(R.drawable.greenstar);

tile3.setBounds(mTileSize*2, 0, mTileSize*3, mTileSize);

tile3.draw(canvas);

canvas.drawBitmap(bitmap, 0, 0, mPaint);

Resources r = this.getContext().getResources();

Bitmap bitmap = Bitmap.createBitmap(mTileSize, mTileSize, Bitmap.Config.ARGB_8888);

Drawable tile1 = r.getDrawable(R.drawable.redstar);

tile1.setBounds(0, 0, mTileSize, mTileSize);

tile1.draw(canvas);

Drawable tile2 = r.getDrawable(R.drawable.yellowstar);

tile2.setBounds(mTileSize, 0, mTileSize*2, mTileSize);

tile2.draw(canvas);

Drawable tile3 = r.getDrawable(R.drawable.greenstar);

tile3.setBounds(mTileSize*2, 0, mTileSize*3, mTileSize);

tile3.draw(canvas);

canvas.drawBitmap(bitmap, 0, 0, mPaint);

由此可见,setBounds的前两个是图片的左上角坐标,后两个是图片右下角的坐标(并不是图片的长和宽)

canvas.drawBitmap(bitmap, 0, 0, mPaint);

改成

canvas.drawBitmap(bitmap, mTileSize, mTileSize, mPaint);

怎么没变化呢?

api解析是

写道

Draw the specified bitmap, with its top/left corner at (x,y), using the specified paint, transformed by the current matrix.

Note: if the paint contains a maskfilter that generates a mask which extends beyond the bitmap's original width/height (e.g. BlurMaskFilter), then the bitmap will be drawn as if it were in a Shader with CLAMP mode. Thus the color outside of the original width/height will be the edge color replicated.

If the bitmap and canvas have different densities, this function will take care of automatically scaling the bitmap to draw at the same density as the canvas.

Parameters

bitmap The bitmap to be drawn

left The position of the left side of the bitmap being drawn

top The position of the top side of the bitmap being drawn

paint The paint used to draw the bitmap (may be null)

--------------------------

新的Tetris不知怎么TextView不能显示在图层之上,就像Snake的状态提示text那样,在SnakeView层之上。

找了半天,才发现原来是Layout搞错了,必须要用FrameLayout才能达到这样的效果,默认的LinearLayout是不行的

上一页  1 2 

 

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

相关文章
  • 学习慕课网canvas倒计时实例笔记

    学习慕课网canvas倒计时实例笔记

    2017-04-30 14:01

  • 从一个画板demo学习canvas

    从一个画板demo学习canvas

    2017-04-30 13:00

  • canvas游戏开发学习之四:应用图像

    canvas游戏开发学习之四:应用图像

    2017-04-29 16:00

  • JS canvas学习笔记

    JS canvas学习笔记

    2017-04-29 15:03

网友点评
h