zoukankan      html  css  js  c++  java
  • android Bitmap旋转问题


    ====================问题描述====================
    //画笔,定义绘制属性
    private Paint myPaint;
    private Paint mBitmapPaint;
    
    // 绘制路径
    private Path myPath;
    
    // 画布及其底层位图
    private Bitmap myBitmap0;
    private Bitmap myBitmap1;
    private Canvas myCanvas;
    public MyPaintView(Context context, AttributeSet attrs){
    super(context, attrs);
    myBitmap0 = BitmapFactory.decodeFile("/storage/sdcard/a.png").copy(Bitmap.Config.ARGB_8888, true);
    myBitmap1 = Bitmap.createBitmap(myBitmap0);
    if(i == 0){
    initialize();
    }else if(i == 1){
    initWhite();
    }
    //开启线程
    new Thread(this).start();
    }
    public void initialize(){
    // 绘制自由曲线用的画笔
    myPaint = new Paint();
    myPaint.setAntiAlias(true);
    myPaint.setDither(true);
    myPaint.setColor(RGBColor.getColor());
    myPaint.setStyle(Paint.Style.STROKE);
    myPaint.setStrokeJoin(Paint.Join.ROUND);
    myPaint.setStrokeCap(Paint.Cap.ROUND);
    myPaint.setStrokeWidth(RGBColor.getFontSize());
    myPath = new Path();
    mBitmapPaint = new Paint(Paint.DITHER_FLAG);
    }
    @Override
    protected void onDraw(Canvas canvas){
    super.onDraw(canvas);
    // 背景颜色
    canvas.drawColor(R.color.white);
     canvas.drawBitmap(myBitmap1, 0, 0, mBitmapPaint);
    
    canvas.drawPath(myPath, myPaint);
    myCanvas = new Canvas(myBitmap1);
    }
    
    /**
    * 图片旋转
     * */
    public void picPost(int nPostExtent){
    matrix.reset();
    matrix.postScale(Scale, Scale);
    matrix.postRotate(nPostExtent);
            // 下面这句话如果把myBitmap1都改为myBitmap0的话顺时针和逆时针旋转都没有问题,现在需要用myBitmap1,是因为在这个位图上面先涂鸦了再旋转的话就会清空以前涂鸦内容,所以选用myBitmap1,但是用它的话只能朝着一个方向旋转,先顺时针完了,逆时针就回不来了
    myBitmap1 = Bitmap.createBitmap(myBitmap1, 0, 0, myBitmap1.getWidth(), myBitmap1.getHeight(), matrix, true);
    }
    

    ====================解决方案1====================
    哦,不是90度角呀,45度角那回不来了。因为图片是在不断变大了,右上角不断填充了白色区域。
    把path存起来,底图不变,每次画图都是底图+path
    或者把path画在一个canvas上,把底图在另一个bitmap上,两个叠加。
  • 相关阅读:
    【算法•日更•第三十四期】最大流算法
    【算法•日更•第三十三期】网络流基础知识(最大流)
    【原】Java学习笔记017
    【原】Java学习笔记016
    【原】Java学习笔记015
    【原】Java学习笔记014
    【原】Java学习笔记013
    【原】Java学习笔记012
    【原】Java学习笔记011
    【原】Java学习笔记010
  • 原文地址:https://www.cnblogs.com/lianxu61/p/4001900.html
Copyright © 2011-2022 走看看