美文网首页
2D学习之Bitmap

2D学习之Bitmap

作者: disilin | 来源:发表于2016-12-19 17:40 被阅读0次

    Canvas canvas =new Canvas();

    Paint paint =new Paint();

    canvas.drawColor(Color.BLACK);

    //-------绘制位图

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

    //-------旋转位图(方式1)

    canvas.save();

    canvas.rotate(30, bitmap.getWidth() /2, bitmap.getHeight() /2);

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

    canvas.restore();

    canvas.drawBitmap(bitmap,100,0, paint);

    //-------旋转位图(方式2)

    Matrix matrix =new Matrix();

    matrix.postRotate(30, bitmap.getWidth() /2, bitmap.getHeight() /2);

    canvas.drawBitmap(bitmap, matrix, paint);

    //-------平移位图(方式1)

    canvas.save();

    canvas.translate(10,10);

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

    canvas.restore();

    //-------平移位图(方式2)

    Matrix matrixT =new Matrix();

    matrixT.postTranslate(10,10);

    canvas.drawBitmap(bitmap, matrixT, paint);

    //-------缩放位图(方式1)

    canvas.save();

    canvas.scale(2f,2f,50+ bitmap.getWidth(),50+ bitmap.getHeight());

    canvas.drawBitmap(bitmap,50,50, paint);

    canvas.restore();

    canvas.drawBitmap(bitmap,50,50, paint);

    //-------缩放位图(方式2)

    Matrix matrixS =new Matrix();

    matrixS.postTranslate(50,50);

    matrixS.postScale(2f,2f,50+ bitmap.getWidth(),50+ bitmap.getHeight());

    canvas.drawBitmap(bitmap, matrixS, paint);

    canvas.drawBitmap(bitmap,50,50, paint);

    //-------镜像翻转位图(方式1)

    //X轴镜像

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

    canvas.save();

    canvas.scale(-1,1,100+ bitmap.getWidth() /2,100+ bitmap.getHeight() /2);

    canvas.drawBitmap(bitmap,100,100, paint);

    canvas.restore();

    //Y轴镜像

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

    canvas.save();

    canvas.scale(1, -1,100+ bitmap.getWidth() /2,100+ bitmap.getHeight() /2);

    canvas.drawBitmap(bitmap,100,100, paint);

    canvas.restore();

    //-------镜像翻转位图(方式2)

    //X轴镜像

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

    Matrix matrixX =new Matrix();

    matrixX.postTranslate(100,100);

    matrixX.postScale(-1,1,100+ bitmap.getWidth() /2,100+ bitmap.getHeight() /2);

    canvas.drawBitmap(bitmap, matrixX, paint);

    //Y轴镜像

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

    Matrix matrixY =new Matrix();

    matrixY.postTranslate(100,100);

    matrixY.postScale(1, -1,100+ bitmap.getWidth() /2,100+ bitmap.getHeight() /2);

    canvas.drawBitmap(bitmap, matrixY, paint);

    相关文章

      网友评论

          本文标题:2D学习之Bitmap

          本文链接:https://www.haomeiwen.com/subject/ncmtvttx.html